Pixel Ledges: 2D Platformer Kit with Sprites, Tilemaps, Wall Jumps and Dash
README.md
parallax
Parallax scrolling backgrounds for 2D games: a stack of picture bands behind the level, each moving at its own fraction of the camera's motion, so far mountains barely move while near hills sweep past.
Each band is one quad that rides with the camera and is resized to cover the view; the picture scrolls inside it (via the pixelParallax.parallax shader; the scrolling itself is the pixelParallax package, this module adds creating a background by catalog id) at the band's factor horizontally (0 = infinitely far, 1 = moves with the level) and its yFactor vertically. Bands are temporary entities each peer draws for itself; nothing is synced. twoDKit.Level2D creates, updates and hides one per level; use this module directly for a background outside a Level2D.
API
Parallax.create(backgroundId, opts?) -> Parallax: spawn the bands of atwoDKit.catalogbackground (grassland,cave,castle,lab,snow,desert, or one you registered; an unknown id falls back to grassland).opts.baseYis the world height the pictures' bottom edge rests on (default 0),opts.depththe z of the farthest band (default -30; nearer bands step toward z = -2),opts.parentan entity to parent the root under.Parallax.update(p, view): move and rescroll every band for a view{ x, y, halfW, halfH }(passtwoDKit.view'scurrent()). Does nothing when the view has not changed.Parallax.setVisible(p, visible): show or hide all bands.Parallax.destroy(p): despawn them.IMAGE_W,IMAGE_H: one background picture in world units (320 x 180 art pixels = 20 x 11.25 tiles).
local Parallax = require("twoDKit.parallax")
local View = require("twoDKit.view")
local bg = Parallax.create("snow", { baseY = 0 })
-- every frame, after the camera moved:
Parallax.update(bg, View.current())
-- when done:
Parallax.destroy(bg)
Every band is created with the shader's stretch flag on, so a band's top and bottom rows extend past its picture.