new Camera( [options])
Creates a new Camera instance.
Parameters:
| Name | Type | Argument | Description | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Configuration options Properties
|
Fires:
Methods
-
copy()
-
Creates a deep copy of the camera instance.
Returns:
A new Camera instance with copied properties
- Type
- Camera
-
deltaZoom(dt, dz [, x] [, y])
-
Applies a relative zoom change at a specific point.
Parameters:
Name Type Argument Default Description dtnumber Animation duration in milliseconds
dznumber Relative zoom change factor
xnumber <optional>
0 X coordinate to zoom around
ynumber <optional>
0 Y coordinate to zoom around
-
fit(box [, dt])
-
Adjusts the camera to frame a specified bounding box.
Parameters:
Name Type Argument Default Description boxBoundingBox The box to frame in canvas coordinates
dtnumber <optional>
0 Animation duration in milliseconds
-
fitCameraBox(dt)
-
Resets the camera to show the entire scene.
Parameters:
Name Type Description dtnumber Animation duration in milliseconds
-
getCurrentTransform(time)
-
Gets the camera transform at a specific time.
Parameters:
Name Type Description timenumber Current time in milliseconds (from performance.now())
Returns:
The interpolated transform at the specified time with isComplete flag
- Type
- Transform
-
getGlCurrentTransform(time)
-
Gets the camera transform at a specific time in device coordinates.
Parameters:
Name Type Description timenumber Current time in milliseconds (from performance.now())
Returns:
The interpolated transform scaled for device pixels
- Type
- Transform
-
glViewport()
-
Returns the current viewport in device coordinates (accounting for device pixel ratio).
Returns:
The current viewport scaled for device pixels
- Type
- Viewport
-
hasReachedTarget(currentTransform)
-
Checks if the camera animation has completed.
Parameters:
Name Type Description currentTransformTransform The current transform (optional, will be calculated if not provided)
Returns:
True if the camera has reached its target position
- Type
- boolean
-
pan(dt, dx, dy)
-
Pans the camera by a specified amount in canvas coordinates.
Parameters:
Name Type Description dtnumber Animation duration in milliseconds
dxnumber Horizontal displacement
dynumber Vertical displacement
-
rotate(dt, a)
-
Rotates the camera around its z-axis.
Parameters:
Name Type Description dtnumber Animation duration in milliseconds
anumber Rotation angle in degrees
-
setPosition(dt, x, y, z, a [, easing])
-
Sets the camera target parameters for a new position.
Parameters:
Name Type Argument Description dtnumber Animation duration in milliseconds
xnumber X component of translation
ynumber Y component of translation
znumber Zoom factor
anumber Rotation angle in degrees
easingstring <optional>
Easing function name for animation
Fires:
-
setViewport(view)
-
Updates the viewport while maintaining the camera position as close as possible to the previous one.
Parameters:
Name Type Description viewViewport The new viewport in CSS coordinates
-
zoom(dt, z [, x] [, y])
-
Zooms the camera to a specific point in canvas coordinates.
Parameters:
Name Type Argument Default Description dtnumber Animation duration in milliseconds
znumber Target zoom level
xnumber <optional>
0 X coordinate to zoom towards
ynumber <optional>
0 Y coordinate to zoom towards