Camera policy / npm 0.1.0
Keep the whole party in frame.
One small, inspectable camera policy for two-to-four-player browser games. Feed it rectangles; get a stable pose, visible safety envelope, and replayable proof.
- 0runtime dependencies
- < 4 KBminified + gzip
- ESM + CJStyped exports
- Fixed-stepreplay proof
Live viewfinder
See the safety margin working.
The vermilion box is the padded safe area. Change the formation or nudge a selected player; the exported camera policy does every piece of framing below.
The live viewfinder displays world-space players, the camera bounds, and a red padded safe area. Current values are repeated in the readout after the canvas.
Focus the viewfinder and use arrow keys to nudge. Press Space to pause.
Calibrating the camera…
Under 30 lines
Own the policy. Keep your renderer.
Coordinates are world pixels, +x right and +y down. The output is a top-left position and a pixels-per-world-pixel zoom—plain values that slot into Phaser, Pixi, Canvas, or WebGL.
- Padding
- Viewport pixels
- Targets
- Axis-aligned rectangles
- Empty list
- Holds the last pose
- World edge
- Camera clamps
import { createCamera } from 'multiplayer-camera-kit'
const camera = createCamera({
viewport: { width: 1280, height: 720 },
world: { x: 0, y: 0, width: 4096, height: 2048 },
padding: 96,
minZoom: 0.5,
maxZoom: 1.5,
})
function tick(dt: number) {
const pose = camera.update(players, dt)
world.position.set(-pose.x * pose.zoom, -pose.y * pose.zoom)
world.scale.set(pose.zoom)
}
Deterministic trace runner
Turn “someone fell off-screen” into a failing test.
Timestamped rectangles are interpolated and replayed at a fixed simulation step. The report names the first target, time, and policy limit that failed.
MCK / replay receipt
Ready to runChoose a known-good trace or a deliberate limit breach.
Policy, not framework
Small enough to audit between playtests.
- 01
Fit the party
Union the target rectangles, reserve screen-space padding, and preserve the viewport aspect ratio.
- 02
Respect the rails
Clamp against world bounds and explicit zoom limits. Impossible framing becomes visible metadata, never a surprise.
- 03
Prove the path
Replay target traces at a fixed step and assert the same safety rule you inspect in development.
MIT licensed / no telemetry