new Camera()
Camera for 2D viewport control. Supports following targets, bounds, shake, and smoothing.
- Source
Members
x
Get the final camera X offset (including shake).
- Source
y
Get the final camera Y offset (including shake).
- Source
Methods
apply(ctx)
Apply the camera transform to the context.
Parameters:
| Name | Type | Description |
|---|---|---|
ctx | CanvasRenderingContext2D |
- Source
clearBounds()
Clear bounds.
- Source
follow(target, offset)
Set the target to follow.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
target | Entity | Entity with Transform component. | |
offset | Vector2 | null | Offset from target center. |
- Source
screenToWorld(screenX, screenY) → {Vector2}
Convert screen position to world position.
Parameters:
| Name | Type | Description |
|---|---|---|
screenX | number | |
screenY | number |
- Source
Returns:
- Type:
- Vector2
setBounds(minX, minY, maxX, maxY)
Set world bounds for the camera.
Parameters:
| Name | Type | Description |
|---|---|---|
minX | number | |
minY | number | |
maxX | number | |
maxY | number |
- Source
setZoom(value)
Set the zoom level of the camera.
Parameters:
| Name | Type | Description |
|---|---|---|
value | number | Zoom level. 1 is default. |
- Source
shake(amount, duration)
Trigger screen shake.
Parameters:
| Name | Type | Description |
|---|---|---|
amount | number | Shake intensity in pixels. |
duration | number | Duration in seconds. |
- Source
transitionTo()
Move the camera to a world position over a fixed duration.
- Source
update(deltaTime)
Update camera position.
Parameters:
| Name | Type | Description |
|---|---|---|
deltaTime | number | Time since last frame. |
- Source
worldToScreen(worldX, worldY) → {Vector2}
Convert world position to screen position.
Parameters:
| Name | Type | Description |
|---|---|---|
worldX | number | |
worldY | number |
- Source
Returns:
- Type:
- Vector2