The pack
follow
function follow(opts: FollowOptions = {}): Pack<{ rig: RigApi }>
The follow-camera rig pack. Moves the camera after physics-2d (rig-follow.camera step) towards the followed
object or objects, with a deadzone, smoothing, an offset, look-ahead, zoom-to-fit, bounds and a cut on teleport,
and returns rig. Requires a 2D world.
Types
FitOptions
interface FitOptions
Zoom-to-fit: while following several objects, zoom so they all stay in view.
padding?: number— World units kept clear between the outermost target and the view's edge. Default 48.minZoom?: number— The furthest out the camera zooms, however far apart the targets are. Default 0.25.maxZoom?: number— The furthest in it zooms, however close together they are. Default 1.
FollowOptions
interface FollowOptions
Manifest options.
deadzone?: number | { w: number; h: number }— The box the target may roam in before the camera moves, world units: a number is a square half-size,{ w, h }a full rectangle. Default 0.smoothing?: number— Fraction of the gap closed per fixed step, 0 locked to 1 instant. Default 0.15.offset?: { x: number; y: number }— World units from the target to the framed point. Default{ x: 0, y: 0 }.lookAhead?: number— Seconds of the target's motion to lead by. Default 0.snapDistance?: number— The one-step jump, world units, treated as a teleport. Default 256; 0 never cuts.fit?: FitOptions— Zoom so several followed objects stay in view. Default off.
RigApi
interface RigApi
game.rig: the follow camera.
follow(h: Handle | readonly Handle[] | null): void— Track this object, or several (the camera frames the middle of them); null stops. Scene-scoped: cleared when the scene exits. A jump oversnapDistancein one step cuts the camera instead of sweeping it.readonly target: Handle | null— The first followed object, or null.readonly targets: readonly Handle[]— Every followed object.deadzone: number | { w: number; h: number }— The box around the screen centre the target may move in before the camera follows: a number is a square half-size,{ w, h }a full rectangle.smoothing: number— 0 = locked, 1 = instant. Per-step smoothing: the camera closes a fraction of the gap each step, so it speeds up to catch a moving target and eases to a stop behind one that stopped. Zoom-to-fit eases at the same rate.offset: { x: number; y: number }— World units from the target to the point the camera frames:{ x: 0, y: -40 }keeps a platformer's hero below the centre.lookAhead: number— Seconds of the target's motion the camera leads by: it looks where the target is going. 0 is none.snapDistance: number— A target that moves further than this in one step has teleported (a respawn, a wrap): the camera cuts with it. 0 never cuts.fit: FitOptions | null— Zoom-to-fit for several targets, or null to leave the zoom alone.bounds(rect: { x: number; y: number; w: number; h: number } | null): void— Clamp the camera so the view never leaves this rect (a tilemap'sbounds()). Scene-scoped.nullclears. A rect smaller than the view centres on it.


