Pixel Ledges: 2D Platformer Kit with Sprites, Tilemaps, Wall Jumps and Dash
README.md
Player2D
A 2D platformer character controller with tight, game-feel movement: running with acceleration and turn-around, variable jump height (hold for a full jump, tap for a short hop), apex hang time, coyote time at ledges, jump buffering, wall slide and wall jump, an 8-way dash with corner correction, drop-through one-way platforms, riding moving platforms, spikes, gem pickups, a goal and a run timer. Every number comes from a swappable movement feel (twoDKit.feels).
Put it on the player's body (the body of the scene's PlayerPrototype) with a twoDKit.Sprite2D beside it, and give the CameraRig a twoDKit.Camera2D. It needs the controlsKit and Trapline packages in the world; levels come from twoDKit.Level2D.
body.component.add("twoDKit.Sprite2D", { character = "knight" })
body.component.add("twoDKit.Player2D", { feel = "tight" })
Controls
It switches on controlsKit's platformer scheme (keyboard, gamepad and touch together) and reads move, jump, dash and crouch. Hold down (or crouch) and press jump on a one-way platform to drop through it. Dash goes in the held direction (8 ways), or the facing direction with no input.
Fields
| Field | Default | Sync | What |
|---|---|---|---|
character | "knight" | yes | knight, robot, fox, mage or a registered id; mirrored onto the Sprite2D, and sets the collision box size. |
feel | "tight" | yes | tight, floaty, heavy, slippery or a feel registered with Feels.register. |
canDash | true | no | Allow the dash. |
canWallJump | true | no | Allow wall slide and wall jump. |
airJumps | 0 | no | Jumps allowed in mid-air (1 = double jump), refilled on landing and on a wall like the dash. Each is the feel's airJumpHeight (default 85% of jumpHeight) high, and plays the airJump moment (a wing-beat puff and a higher jump sound). |
canSlam | false | no | Allow the down-slam: a fresh press of down (crouch, or the stick past half-way down) in the air drives straight down at the feel's slamSpeed (default 30 tiles/s), with no steering and no gravity, until the ground; moments slam and slamLand (dust ring, heavy shake, hard-landing sound). Down + jump standing on a one-way platform still drops through. |
move | "" | yes | Read-only: the last mid-air move as kind:count[:ground] (airJump, slam, slamLand); every peer plays its moment when it changes. |
scheme | "platformer" | no | controlsKit scheme switched on for this player ("" leaves the active scheme alone). |
planeZ | 0 | no | Depth the player is held to (the level's plane). |
hazards | true | no | Level spikes cost a life through Trapline. |
gems | 0 | yes | Gems collected (Level2D o cells). |
finished | false | yes | Reached a goal (G). |
runTime | 0 | yes | Seconds from the first move or jump to the goal. |
deaths | 0 | yes | Lives lost this run. |
Methods
setFeel(id),setCharacter(id): switch live; both sync.teleport(x, y): put the player's feet at a world point, at rest.bounce(speed): launch upward atspeedtiles/s and refill the dash (springs, bounce pads). Call it on the owning peer.state(): the motor on the owning peer:x, y, vx, vy, grounded, wall, dashes, dashing, facing, dead, coyote, buffer, ground, andairJumpsLeft,slamming,slamGround(the entity the last slam landed on),slamAt(when, on the motor'sclock, also returned).bounce(speed)also ends a slam.resetRun(): gems, timer, goal and deaths back to zero; this player's gems reappear.hasGem("<levelId>:<index>"): has this player taken that gem?
How it works
The motor runs at a fixed 60 Hz step on the peer that owns the body only, moving an axis-aligned box with the engine's Physics.boxCast, so it stands on Level2D ground, one-way platforms, platformsKit moving platforms (and rides them) and any other collider. It writes the body's position (the engine replicates the avatar) and the Sprite2D's synced anim and facing, so every peer sees every player run, jump, wall slide and dash. A dash refills on the ground and when sliding down a wall; jumping into a ceiling corner slides around it by up to 4 pixels, and a horizontal dash into a ledge lip steps up over it.
Spikes call Trapline hit (one hit per second at most) and the body blinks; a fall lands in the level's Trapline kill zone; while Trapline reports the player dead it holds still in the hurt animation, and when a respawn moves the body the motor restarts from rest at the new spot. Gems and the goal are collected by overlap with this player's box, per player.