new EntityBoxCamera(entity, width, height, screenCenterX, screenCenterY)
A Splat.Camera that tracks an Splat.Entity to keep it on screen within an invisible box. If the Entity moves outside of the invisible box, the camera is adjusted the minimal amount so that the Entity is back inside the box.
Parameters:
Name | Type | Description |
---|---|---|
entity |
Splat.Entity | The Entity for the camera to track. |
width |
number | The width of the invisible box to keep the Splat.Entity within. |
height |
number | The height of the invisible box to keep the Splat.Entity within. |
screenCenterX |
number | The center of the invisible box on the screen along the x axis. |
screenCenterY |
number | The center of the invisible box on the screen along the y axis. |
- Source:
Example
var scene = new Splat.Scene(canvas, function() {
// initialization
this.player = new Splat.Entity(200, 200, 50, 50);
// make a camera that won't let the player closer than 100 pixels to the left and right sides, or 50 pixels from the top or bottom
this.camera = new Splat.EntityBoxCamera(this.player, canvas.width - 200, canvas.height - 100, canvas.width / 2, canvas.height / 2);
}, function(elapsedMillis) {
// simulation
}, function(context) {
// draw
});
Extends
Members
entity :Splat.Entity
The Splat.Entity for the camera to track.
Type:
- Source:
height :number
Height of the Entity, extending downward from Splat.Entity#y.
Type:
- number
- Inherited From:
- Source:
(readonly) lastX :number
The value of Splat.Entity#x in the previous frame.
Type:
- number
- Inherited From:
- Source:
(readonly) lastY :number
The value of Splat.Entity#y in the previous frame.
Type:
- number
- Inherited From:
- Source:
screenCenterX :number
The center of the invisible box on the screen along the x axis.
Type:
- number
- Source:
screenCenterY :number
The center of the invisible box on the screen along the y axis.
Type:
- number
- Source:
vx :number
Velocity along the x-axis in pixels/millisecond.
Type:
- number
- Inherited From:
- Source:
vy :number
Velocity along the y-axis in pixels/millisecond.
Type:
- number
- Inherited From:
- Source:
width :number
Width of the Entity, extending to the right of Splat.Entity#x.
Type:
- number
- Inherited From:
- Source:
x :number
Leftmost position along the x-axis.
Type:
- number
- Inherited From:
- Source:
y :number
Topmost position along the y-axis.
Type:
- number
- Inherited From:
- Source:
Methods
collides(other) → {boolean}
Test if this Entity is currently colliding with another.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity | The Entity to test for collision with |
- Inherited From:
- Source:
Returns:
- Type
- boolean
didOverlapHoriz(other) → {boolean}
Test if this Entity horizontally overlapped another in the previous frame.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity | The Entity to test for overlap with |
- Inherited From:
- Source:
Returns:
- Type
- boolean
didOverlapVert(other) → {boolean}
Test if this Entity vertically overlapped another in the previous frame.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity | The Entity to test for overlap with |
- Inherited From:
- Source:
Returns:
- Type
- boolean
getCollisions(entities) → {Array}
Return a list of all Entities that collide with this Entity.
Parameters:
Name | Type | Description |
---|---|---|
entities |
Array | A list of Entities to check for collisions. |
- Inherited From:
- Source:
Returns:
A list of entities that collide with this Entity.
- Type
- Array
move()
Adjust the camera so that it keeps Splat.EntityBoxCamera#entity within the invisible box. This is usually automatically called by the Splat.Scene for you.
- Overrides:
- Source:
moved() → {boolean}
Test if this Entity has changed position since the previous frame.
- Inherited From:
- Source:
Returns:
- Type
- boolean
overlapsHoriz(other) → {boolean}
Test if this Entity horizontally overlaps another.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity | The Entity to test for overlap with |
- Inherited From:
- Source:
Returns:
- Type
- boolean
overlapsVert(other) → {boolean}
Test if this Entity vertically overlaps another.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity | The Entity to test for overlap with |
- Inherited From:
- Source:
Returns:
- Type
- boolean
resolveBottomCollisionWith(other)
Adjust the Entity's position so its bottom edge does not penetrate the other Entity's top edge.
Splat.Entity#vy is also zeroed.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity |
- Inherited From:
- Source:
resolveCollisionWith(other)
Adjust the Entity's position so it does not penetrate the other Entity.
Splat.Entity#vx will be zeroed if Splat.Entity#x was adjusted, and Splat.Entity#vy will be zeroed if Splat.Entity#y was adjusted.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity |
- Inherited From:
- Source:
resolveLeftCollisionWith(other)
Adjust the Entity's position so its left edge does not penetrate the other Entity's right edge.
Splat.Entity#vx is also zeroed.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity |
- Inherited From:
- Source:
resolveRightCollisionWith(other)
Adjust the Entity's position so its right edge does not penetrate the other Entity's left edge.
Splat.Entity#vx is also zeroed.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity |
- Inherited From:
- Source:
resolveTopCollisionWith(other)
Adjust the Entity's position so its top edge does not penetrate the other Entity's bottom edge.
Splat.Entity#vy is also zeroed.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity |
- Inherited From:
- Source:
solveCollisions(entities) → {Array}
Detect and resolve collisions between this Entity and a list of other Entities
Parameters:
Name | Type | Description |
---|---|---|
entities |
Array | A list of Entities to solve against. |
- Inherited From:
- Source:
Returns:
A list of entities that were involved in collisions.
- Type
- Array
wasAbove(other) → {boolean}
Test if this Entity was above another in the previous frame.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity | The Entity to test for above-ness with |
- Inherited From:
- Source:
Returns:
- Type
- boolean
wasBelow(other) → {boolean}
Test if this Entity was below another in the previous frame.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity | The Entity to test for below-ness with |
- Inherited From:
- Source:
Returns:
- Type
- boolean
wasLeft(other) → {boolean}
Test if this Entity was to the left of another in the previous frame.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity | The Entity to test for left-ness with |
- Inherited From:
- Source:
Returns:
- Type
- boolean
wasRight(other) → {boolean}
Test if this Entity was to the right of another in the previous frame.
Parameters:
Name | Type | Description |
---|---|---|
other |
Splat.Entity | The Entity to test for right-ness with |
- Inherited From:
- Source:
Returns:
- Type
- boolean