@fogrexon/glyph-arena-camera

2D camera state and world-to-screen view matrix. See also package README.

Exports

Generated from the package's source when the docs are built — do not edit this table by hand.

NameKind
Cameratype
CameraStatetype
Matrix2Dtype
createCamerafunction

createCamera()

const camera = createCamera();

camera.set({ x: 100, y: 50, rotation: Math.PI / 4, zoom: 2 });
const state = camera.get();
const matrix = camera.view(800, 600);
camera.dispose();

Methods

CameraState

FieldDefaultDescription
x0camera center X in world space
y0camera center Y in world space
rotation0rotation in radians
zoom1isotropic scale (sx = sy = zoom)

Defaults: { x: 0, y: 0, rotation: 0, zoom: 1 }.

Matrix2D

Canvas 2D affine matrix (a, b, c, d, e, f) compatible with CanvasRenderingContext2D.setTransform.

View matrix

view(width, height) composes as T(width/2, height/2) × R × S(zoom) × T(−x, −y) — camera inverse translate, isotropic scale, rotate, then translate to screen center. The camera center maps to the screen center.

Negative zoom passes through as a flip. Zero zoom passes through (scale terms become zero).

After dispose()