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 dt
number Animation duration in milliseconds
dz
number Relative zoom change factor
x
number <optional>
0 X coordinate to zoom around
y
number <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 box
BoundingBox The box to frame in canvas coordinates
dt
number <optional>
0 Animation duration in milliseconds
-
fitCameraBox(dt)
-
Resets the camera to show the entire scene.
Parameters:
Name Type Description dt
number Animation duration in milliseconds
-
getCurrentTransform(time)
-
Gets the camera transform at a specific time.
Parameters:
Name Type Description time
number Current time in milliseconds (from performance.now())
Returns:
The interpolated transform at the specified time
- Type
- Transform
-
getGlCurrentTransform(time)
-
Gets the camera transform at a specific time in device coordinates.
Parameters:
Name Type Description time
number 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
-
mapToScene(x, y, transform)
-
Converts canvas coordinates to scene coordinates using the specified transform.
Parameters:
Name Type Description x
number X coordinate relative to canvas
y
number Y coordinate relative to canvas
transform
Transform Transform to use for conversion
Returns:
Coordinates in scene space relative to viewport center
- Type
- Object
-
pan(dt, dx, dy)
-
Pans the camera by a specified amount in canvas coordinates.
Parameters:
Name Type Description dt
number Animation duration in milliseconds
dx
number Horizontal displacement
dy
number Vertical displacement
-
rotate(dt, a)
-
Rotates the camera around its z-axis.
Parameters:
Name Type Description dt
number Animation duration in milliseconds
a
number Rotation angle in degrees
-
sceneToCanvas(x, y, transform)
-
Converts scene coordinates to canvas coordinates using the specified transform.
Parameters:
Name Type Description x
number X coordinate in scene space
y
number Y coordinate in scene space
transform
Transform Transform to use for conversion
Returns:
Coordinates in canvas space
- Type
- Object
-
setPosition(dt, x, y, z, a [, easing])
-
Sets the camera target parameters for a new position.
Parameters:
Name Type Argument Description dt
number Animation duration in milliseconds
x
number X component of translation
y
number Y component of translation
z
number Zoom factor
a
number Rotation angle in degrees
easing
string <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 view
Viewport 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 dt
number Animation duration in milliseconds
z
number Target zoom level
x
number <optional>
0 X coordinate to zoom towards
y
number <optional>
0 Y coordinate to zoom towards