Log inGet started
World

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

README.md

pixelParallax: pixel-crisp parallax backgrounds

Backgrounds that scroll behind a 2D scene at different depths, far layers barely moving and near ones sweeping past, in any Zero world, with no other kit. It is the background layer of twoDKit (all its ten themed backgrounds run on it) and works on its own.

  • ParallaxBackground component: up to four layers, sky, far, mid and near, each a picture with a factor (how much of the camera's motion it follows: 0 = fixed, 1 = moves with the scene). It follows whichever camera is rendering, or the one you name.
  • parallax module: the same for any number of layers, driven by your own camera code: create(layers, opts), update(p, view), setVisible, destroy, and bandUV (the pixel-exact texture mapping).
  • parallax shader: unlit, alpha-cut, nearest-filtered; repeats each picture sideways.

Scrolling is rounded to whole screen pixels measured from the view's edges, so a background pixel is exactly as big and as still as a tile pixel at any window size. Depends on pixelSprites (for the quad), which installs with it.

Install

tools.use("zeromind", "installAsset", "81b13a43-8a9b-4a93-a4ca-4c09c5194dbe")   -- or `zero zeromind installAsset 81b13a43-8a9b-4a93-a4ca-4c09c5194dbe` in the shell

or search ZeroMind for "pixelParallax" / "parallax background".

Your first background

Each layer picture is 320 x 180 pixels (20 x 11.25 world units at 16 per unit), with transparent sky in the nearer layers, and a material on the pixelParallax.parallax shader:

function content()
    local bg = entity.spawn("Background")
    bg.component.add("pixelParallax.ParallaxBackground", {
        sky = asset.resolve("my.art.sky", "material"), skyFactor = 0,
        far = asset.resolve("my.art.mountains", "material"), farFactor = 0.15,
        mid = asset.resolve("my.art.hills", "material"), midFactor = 0.35,
        near = asset.resolve("my.art.trees", "material"), nearFactor = 0.6,
        baseY = 0,
    })
end

ParallaxBackground fields

FieldDefaultWhat
sky, far, mid, nearnoneLayer materials, far to near; leave any empty.
skyFactor, farFactor, midFactor, nearFactor0, 0.15, 0.35, 0.6Share of the camera's motion each layer follows (vertically half of it).
baseY0World height of the pictures' bottom edge when the camera is at height 0.
depth-30Depth of the farthest layer; the others stand in front of it.
cameraemptyThe camera to follow; empty = the one the renderer is using.
viewHeight11.25View height used when that camera is not orthographic.

With your own camera

local Parallax = require("pixelParallax.parallax")
local p = Parallax.create({ { material = sky, factor = 0 }, { material = hills, factor = 0.3 } }, { baseY = 0 })
-- every frame, after the camera moved (halfW / halfH in world units, zoom = screen pixels per art pixel):
Parallax.update(p, { x = camX, y = camY, halfW = hw, halfH = hh, zoom = zoom })

Every peer draws its own background on temporary entities; nothing is synced or saved.

Changelog

  • 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; the parallax shader has a preview picture; built on the engine's library d4061d2.
  • 1.0.1: real install lines in the README.
  • 1.0.0: first release, split out of twoDKit 1.1.0: the ParallaxBackground component, the parallax module (with anchorY, so a level placed above the origin shows its background) and the parallax shader.