Syncromesh/Camera
Camera positioning, framing, scaling, and animations.
Controls the 2D camera that determines what portion of the world is visible. Supports smooth tweening of position and frame size, plus keyframe animations for effects like screen shake. You can explicitly bind camera operations to a specific window via setWindow(windowId) so camera control remains stable even if board attachments change.
Import #
import * as Camera from 'Syncromesh/Camera';Functions #
setWindow
Sets the explicit target window for all camera operations in the current script context.
- Use this in multi-board scripts so camera control is independent of board attach/detach.
setWindow(windowId: number): Promise<void>getWindow
Returns the currently configured camera window ID, or
null if none is explicitly set.getWindow(): Promise<number | null>clearWindow
Clears explicit window targeting and reverts to board/window inference.
clearWindow(): Promise<void>getPosition
Returns the camera's current center position in world space.
getPosition(): Promise<Point>getFrame
Returns the camera's current frame size (visible area in world units).
getFrame(): Promise<Point>setPosition
Moves the camera to a target position over
duration seconds.- Set
durationto0for an instant jump.
setPosition(target: Point, duration: number): Promise<void>setFrame
Resizes the camera's visible area over
duration seconds.- Set
durationto0for an instant change.
setFrame(size: Point, duration: number): Promise<void>setFrameScale
Uniformly scales the camera frame by a factor over
duration seconds.- Values
< 1zoom in; values> 1zoom out.
setFrameScale(scale: number, duration: number): Promise<void>addAnimation
Adds a keyframe animation to the camera and returns its animation ID.
- See Animation for the keyframe format.
addAnimation(keyframes: KeyFrame[]): Promise<number>startAnimation
Starts playback of a camera animation by ID.
startAnimation(animationId: number): Promise<void>onAnimationEnd
Registers a callback invoked when the camera animation completes.
onAnimationEnd(animationId: number, callback: (time: number): void) : Promise<void>Examples #
Pan to a target, apply a zoom, and play a screen-shake animation:
import * as Camera from 'Syncromesh/Camera';
// Optional: pin camera control to a specific window.
await Camera.setWindow(windowId);
// Instant jump
await Camera.setPosition({ x: 50, y: 50 }, 0);
// Smooth pan over 1 second
await Camera.setPosition({ x: 200, y: 100 }, 1.0);
// Zoom in
await Camera.setFrameScale(0.5, 0.3);
// Screen shake animation
const shake = await Camera.addAnimation([
{ time: 0, noise: { type: 'whiteNoise', position: { x: 0.5, y: 0.5 }, scale: { x: 2, y: 2 } } },
{ time: 0.3, noise: { type: 'whiteNoise', position: { x: 0, y: 0 }, scale: { x: 0, y: 0 } } }
]);
await Camera.startAnimation(shake);
await Camera.onAnimationEnd(shake, (time) => {
// Shake finished
});