Constructor
# new Camera(context, frames)
Create new camera.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
context |
CanvasRenderingContext2D
|
the canvas rendering context | |
frames |
number
|
0 | counter to control the frequency of updates |
Classes
Members
Methods
# preRender(entity) → {void}
Adjust the camera's position based on the passed entity's position.
This method calculates the offset needed to center the entity on the screen
and applies a translation to the rendering context to simulate camera movement.
Parameters:
Name | Type | Description |
---|---|---|
entity |
Object
|
the game entity (usually the player) |
void
# update(player, entities) → {void}
Update the camera and rendering state for entities.
This method increments the frame counter and, when reaching a certain threshold,
calculates the new screen object based on the player's position and the canvas
dimensions. It checks each entity's bounding box or bounding circle against the
screen to determine if they are within the visible area. Entities outside the
visible area are flagged as sleep and not updated.
Parameters:
Name | Type | Description |
---|---|---|
player |
Player
|
the player entity |
entities |
array
|
array of game entities |
void