Log inGet started
World

Pixel Ledges: 2D Platformer Kit with Sprites, Tilemaps, Wall Jumps and Dash

README.md

pixelSprites: animated pixel-art sprites from any sprite sheet

Draw a character or object as a flat pixel-art picture that plays named animations from a sprite sheet, in any Zero world, with no other kit. It is the sprite layer of twoDKit and works on its own.

  • SpriteSheet component: name your animations once as rows of the sheet ("idle=0:6:8, run=1:8:14, jump=2:3:12:once"), then switch with one field (anim). It faces left or right (facing), stays snapped to the art's pixel grid so it never shimmers, and anim and facing sync, so every player sees every other player's animation.
  • sprites module: attach a picture showing one cell of a sheet to any entity and drive it yourself: setCell, setFlash (hit flash), setFade (dithered fade), setTint, setSquash (squash and stretch that stays pixel-crisp), snapTo.
  • sprite shader: unlit, alpha-cut, nearest-filtered; one material draws every sprite that uses the sheet.

Install

tools.use("zeromind", "installAsset", "af866662-98d1-4500-bd67-49508538bb47")   -- or `zero zeromind installAsset af866662-98d1-4500-bd67-49508538bb47` in the shell

or search ZeroMind for "pixelSprites" / "animated sprite sheet". It lands at /source/pixelSprites.package.

Your first animated sprite

A sheet is a texture with the frames in a grid, top row first, and a material on the pixelSprites.sprite shader. Make the material by importing your sheet as a texture (nearest filter) and creating a material whose shader is pixelSprites.sprite with that texture as its base colour, or paint one in code with twoDKit's twoDKit.paint (Paint.save then Paint.material). With one in hand:

function content()
    local hero = entity.spawn("Hero", { position = { 0, 1, 0 } })   -- the position is the feet
    hero.component.add("pixelSprites.SpriteSheet", {
        sheet = asset.resolve("my.art.hero", "material"),
        frameWidth = 32, frameHeight = 32, columns = 8, rows = 8,
        animations = "idle=0:6:8, run=1:8:14, jump=2:3:12:once, fall=3:3:10",
    })
end

Then, from your own code: hero.component.get("pixelSprites.SpriteSheet").anim = "run" and .facing = -1 to face left. :play("jump", true) restarts an animation, :isFinished() says whether a :once animation reached its last frame.

SpriteSheet fields

FieldDefaultWhat
sheetnoneThe material (on the pixelSprites.sprite shader).
frameWidth, frameHeight32One frame in pixels.
columns, rows8The sheet's grid.
animationsidle=0:1:1name=row:frames:fps, add :once to hold the last frame; rows count from the top, starting at 0.
animidleThe animation playing (synced).
facing11 as drawn, -1 mirrored (synced).
speed1Animation speed multiplier.
pixelsPerUnit16Art pixels per world unit.
pixelSnaptrueKeep the picture on the art's pixel grid.
z0Depth offset.

Notes

  • The picture is drawn on a temporary child entity on each peer; nothing about it is saved or sent except anim and facing.
  • For crisp pixels on screen use an orthographic camera whose height is the window height divided by a whole number of screen pixels per art pixel (twoDKit's Camera2D does this, and pixelParallax scrolls backgrounds to match).
  • The engine's own flipbook (animatedTexture) plays texture layers on a clock; it cannot pick named animations or mirror, which is why this package exists.

Changelog

  • 1.1.0: a SpriteSheet can take a plain sprite-sheet texture (texture) instead of a material; pixelSprites builds the sprite material from it at runtime (Sprites.sheetMaterial), so a game ships the texture alone, with no material asset or material preview per sheet. sheet works exactly as before.
  • 1.0.3: this changelog. No change to the component, module or shader.
  • 1.0.2: the package description says what it gives you and how to install it.
  • 1.0.1: real install lines in the README, and how to make a sheet material.
  • 1.0.0: first release, split out of twoDKit 1.1.0: the SpriteSheet component, the sprites module and the sprite shader.