Pixel Ledges: 2D Platformer Kit with Sprites, Tilemaps, Wall Jumps and Dash
README.md
Camera2D
A pixel-perfect 2D platformer camera behaviour: it follows the player with a dead zone, smooth look-ahead or room-by-room screens, stays inside the level, and keeps pixel art crisp with no shimmer at any window size (integer zoom, position snapped to the pixel grid, antialiasing off).
It is a camera behaviour (tagged cameraBehavior): put it on the CameraRig under the scene's PlayerPrototype, next to the engine Camera that names it as its behavior. The Camera's follow names the body to track (the engine binds it per player), so each peer's camera follows its own player only. It works with twoDKit.Level2D levels (bounds, per-level camera style, room size) and publishes its view to twoDKit.view for the parallax backgrounds.
rig.component.add("Camera", { behavior = asset.resolve("twoDKit.Camera2D", "component"), projection = "orthographic" })
rig.component.add("twoDKit.Camera2D", { style = "smooth", targetHeight = 216 })
Styles
pixelPerfect: tight dead zone, quick catch-up, the view snapped to the art's pixel grid (1/16 tile): the classic crisp look.smooth: eased follow leading up tolookAheadtiles in the direction of travel, snapped to screen pixels (crisp, but glides).rooms: holds a screen-sized room (Level2D.roomWidthxroomHeight, default 20 x 12 tiles) and slides to the next when the player crosses its edge (Celeste-style screens).
A Level2D's camera field overrides style while the player is in that level.
Fields (all local, not synced)
| Field | Default | What |
|---|---|---|
style | pixelPerfect | pixelPerfect, smooth or rooms. |
targetHeight | 216 | About how many art pixels tall the view is; zoom = the whole number nearest window height / this (at least 1). |
minWidth | 240 | At least about how many art pixels wide the view is: when window width / this is smaller than window height / targetHeight (a phone held upright), the zoom follows the width instead. 0 = height only. |
lookAhead | 2.5 | Tiles the smooth camera leads by. |
deadZoneX / deadZoneY | 1.0 / 1.5 | Half-size in tiles of the pixelPerfect dead zone (the lower edge is 60% of deadZoneY). |
smoothing | 6 | Catch-up rate of smooth and rooms (higher = snappier). |
clampToLevel | true | Never show anything outside the level the player is in: the zoom is raised by whole steps for a level smaller than the view, and the snapped view is kept inside the level's edges. |
crisp | true | Turn off temporal and edge antialiasing and hold render scale at 1 on this peer, once. |
depth | 30 | Distance of the camera in front of the level plane. |
shake | 0 | Screen shake in tiles; decays at 3 tiles per second. |
Methods
addShake(amount): shake by at leastamounttiles (raisesshake, never lowers it).recenter(): jump straight to the player next frame, no easing (after a respawn or teleport).
Every frame it forces an orthographic projection, sets orthoHeight from the zoom, keeps the camera unrotated at z = depth, and sets near 0.1 / far depth + 80.