Skip to content

CameraControls ​

The contract between a viewport and its camera controls.

Implement this interface to drive a camera with custom input logic and assign it to a viewport through its cameraControls property. The viewport passes pointer and wheel events to onEvent unless a layer stops propagation.

ts
class ClickToZoomControls implements CameraControls {
  constructor(private camera: OrthographicCamera) {}

  get isMoving() {
    return false;
  }

  onUpdate(dt: number) {}

  onEvent(event: EventContext) {
    if (event.type === "pointerdown") this.camera.zoom(2);
  }
}

viewport.cameraControls = new ClickToZoomControls(camera);

Implemented by ​

Properties ​

isMoving ​

Whether the camera is in motion from user interaction. Layers may read this to reduce rendering quality while the view changes.

ts
readonly isMoving: boolean;

Methods ​

onUpdate() void ​

Advances time-based motion such as damping. Called automatically by the render loop.

ts
onUpdate(dt): void;
ParameterDescription
dt: numberTime since the last frame in seconds.

onEvent() void ​

Handles a pointer or wheel event. Called automatically by the owning viewport unless a layer stops propagation.

ts
onEvent(event): void;
ParameterDescription
event: EventContextThe event with clip and world coordinates attached.

Released under the MIT License