Members
x :number
The x-coordinate of the camera's top-left corner in world space.
This is effectively the viewportX offset.
Type:
- number
- Source:
y :number
The y-coordinate of the camera's top-left corner in world space.
This is effectively the viewportY offset.
Type:
- number
- Source:
Methods
getViewportX() → {number}
Gets the current x-coordinate of the viewport (camera's top-left x in world space).
- Source:
Returns:
- Type
- number
getViewportY() → {number}
Gets the current y-coordinate of the viewport (camera's top-left y in world space).
- Source:
Returns:
- Type
- number
setTarget(targetEntity, screenFocusXopt, screenFocusYopt)
Sets the target entity for the camera to follow.
The target should either have direct worldX, worldY, width, height properties,
OR have getPosition() and getDimensions() methods.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
targetEntity |
object | null | The entity or object to follow. | |
screenFocusX |
number |
<optional> |
Optional: The x-coordinate on screen where the target should be centered. |
screenFocusY |
number |
<optional> |
Optional: The y-coordinate on screen where the target should be centered. |
- Source:
setViewportDimensions(viewportWidth, viewportHeight)
Updates the dimensions of the camera's viewport (e.g., if canvas is resized).
Parameters:
Name | Type | Description |
---|---|---|
viewportWidth |
number | The new width of the viewport. |
viewportHeight |
number | The new height of the viewport. |
- Source:
setWorldDimensions(worldWidth, worldHeight)
Updates the dimensions of the game world.
Parameters:
Name | Type | Description |
---|---|---|
worldWidth |
number | The new total width of the game world. |
worldHeight |
number | The new total height of the game world. |
- Source:
update()
Updates the camera's position. If a target is set, it follows the target.
Also clamps the camera to the world boundaries.
- Source: