Phaser AE

Grid lane movement

Free packv3.0.0-42DPhysics

Four-way movement along the lanes of a tile grid: from tile centre to tile centre, turning only at junctions, the way maze chases and bomb-laying games move. Put a sprite on the lanes, say what is a wall, and the steering, cornering and stopping are done for you.

This is a Free pack. Every phaser.io account can use it in their games.

Released October 14, 2026 · updated October 19, 2026

Grid lane movement: a screenshot of its demo
A note about these graphics

Expansion packs don't come with graphics. This screenshot is one way of drawing what the pack does, made for its demo: none of the sprites, tiles or backgrounds in it are in the pack.

That's by design. A pack is a game's logic, mechanics and effects, and it works with whatever art you give it. Some packs draw effects, backdrops or 3D scenes of their own, but none carries a game's sprites.

So the look is yours. Make the art on phaser.io, bring your own, or let your agent draw it in code: the same pack can look like anything.

The pack

gridMove

function gridMove(opts: GridMoveOptions = {}): Pack<{ grid: GridMoveApi }, {}, { grid: GridData }>

Lane movement on a tile grid. Runs before physics-2d: with a body it sets body.vx/vy, without one it moves x/y itself.

Types

GridData

interface GridData

The grid columns: the direction moving and the direction wanted, each −1, 0 or 1 per axis.

  • readonly dx: number — x direction moving: −1, 0, 1.
  • readonly dy: number — y direction moving: −1, 0, 1.
  • readonly wx: number — x direction wanted: −1, 0, 1.
  • readonly wy: number — y direction wanted: −1, 0, 1.

GridKeys

interface GridKeys

Key codes per direction for a lane read from the keyboard.

  • up?: string[] — Keys that steer up (y −1).
  • down?: string[] — Keys that steer down (y +1).
  • left?: string[] — Keys that steer left (x −1).
  • right?: string[] — Keys that steer right (x +1).

GridMoveApi

interface GridMoveApi

game.grid. Every call but lane throws grid-move: <id> is not on a lane for a handle that was never laned.

  • createGridWalker: typeof createGridWalker — Pure, renderer-independent arcade lane walker; positions use tile centres.
  • lane(h: Handle, spec: LaneSpec): void — Put a handle on the lanes. Undone when the scene exits or the handle dies.
  • want(h: Handle, dx: number, dy: number): void — Set the wanted direction (for input: 'manual'; with keys it holds only while no key is down). Signs are taken.
  • halt(h: Handle): void — Stop (zeroing the body's velocity if it has one) and forget the wanted direction.
  • cell(h: Handle): { c: number; r: number } — The tile the handle's nearest lane centre is in.
  • centre(h: Handle, c: number, r: number): { x: number; y: number } — The world position of a tile's centre.
  • free(h: Handle, dx: number, dy: number): boolean — Could the handle move one tile that way from its nearest lane? (the game's walls, not the physics)
  • canGo(h: Handle, dx: number, dy: number): boolean — May it move that way from where it is right now? free, or the lane centre is still ahead.
  • laneX(h: Handle): number — Nearest lane centre x to the handle, world units.
  • laneY(h: Handle): number — Nearest lane centre y to the handle, world units.

GridMoveOptions

interface GridMoveOptions

Manifest options; every one may be overridden per lane.

  • tile?: number — Tile size in px. Default 16.
  • originX?: number — World x of tile (0,0)'s top-left corner. Default 0.
  • originY?: number — World y of tile (0,0)'s top-left corner. Default 0.
  • turnTolerance?: number — How far off the lane (px) a turn is still taken. Default 3.
  • assist?: number — Cornering assist reach: slide toward the lane when within this many px of it. 0 disables. Default tile/2.

LaneSpec

interface LaneSpec

What lane() takes: the walls, the speed and how it is steered.

  • walls: (c: number, r: number) => boolean — Is tile (c, r) solid? Called every step, for cells outside the grid too.
  • speed: number — px/s.
  • mode?: 'remember' | 'held' — remember: a press keeps going until a wall (Pac-Man). held: move while held, stop on release. Default remember.
  • input?: 'keys' | 'manual' — keys: the pack steers from the keyboard itself (most recent key wins; keys names them, default arrows and WASD). manual: the game calls want(). Default keys.
  • tile?: number — Tile size in px, overriding the pack option.
  • originX?: number — World x of tile (0,0)'s top-left, overriding the pack option.
  • originY?: number — World y of tile (0,0)'s top-left, overriding the pack option.
  • turnTolerance?: number — Turn tolerance in px, overriding the pack option.
  • assist?: number — Cornering assist reach in px, overriding the pack option.
  • keys?: GridKeys — The key codes (KeyboardEvent.code) for each direction when input is keys. Default arrows plus WASD; a direction left out has no keys.