PanCamera2DController

View source

Camera controls for 2D scenes.

A left-button drag pans the camera, a right- or middle-button drag rotates it around the Z axis, and the wheel zooms. On touch devices one finger pans while a two-finger gesture pans, zooms, and rotates at the same time.

Zoom is applied through the camera transform scale, so the controller works with an orthographic projection without taking ownership of its bounds.

Constructor


constructor ( camera: Camera , targetElement?: EventTarget )

View source

Parameters

Name Description Default
camera — —
targetElement? — —

Properties


zoom : number

View source

Camera zoom multiplier. Values above one zoom in.

Default: 1

rotation : number

View source

Camera rotation around the Z axis, in radians.

Default: 0

panSensitivity : number

View source

Multiplier applied to the screen-to-world pan distance.

Default: 1

Methods


syncFromCamera ( ) : PanCamera2DController

View source

Synchronizes the controller with the camera’s current orientation and scale. Calling this resets the controller zoom to one.

updateMouseInput ( ) : void

View source

Applies the current mouse drag to the camera.

onTouchMove ( event: PointerEvent , previousX: number , previousY: number ) : void

View source

Parameters

Name Description Default
event — —
previousX — —
previousY — —

onWheel ( event: WheelEvent ) : void

View source

Parameters

Name Description Default
event — —

applyPanFromScreenDelta ( deltaX: number , deltaY: number ) : void

View source

Applies a screen-space drag to the camera position. The Y direction is inverted so content follows the pointer in the viewport.

Parameters

Name Description Default
deltaX — —
deltaY — —