Phaser AE

Fog of war

Free packv3.0.0-32DLogic

Fog of war on a tile grid: lights that cast shadows off walls, a brightness for every cell, and a memory of where the player has been. Your game asks each cell whether it is unseen, explored or visible and draws it however it likes.

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

Released October 14, 2026 · updated October 19, 2026

Fog of war: 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

fog

function fog(): Pack<{ fog: FogApi }>

The fog-of-war pack: a factory for FogGrids. Headless, no columns, no passes.

Classes

FogGrid

class FogGrid

A fog-of-war grid: recursive shadowcasting over opaque cells from any number of lights, a brightness per cell, and a memory of what has been seen. Headless; the game draws it (a dark tile per cell by state(), or an alpha from lightAt()).

  • readonly cols: number — Columns.
  • readonly rows: number — Rows.
  • falloff: FogFalloff — Default falloff for lights without their own.
  • memory: boolean — Remember explored cells.
  • readonly opaque: Uint8Array — 1 where a cell blocks light; cols × rows, row-major.
  • readonly light: Float32Array — Brightness 0..1 per cell after compute().
  • readonly explored: Uint8Array — 1 where a cell has ever been lit (when memory).
  • readonly lights: FogLight[] — The lights. addLight appends; mutate and compute().
  • constructor(opts: FogGridOptions) — Build an empty, dark grid. Sizes are floored and at least 1.
  • index(col: number, row: number): number — Row-major index of a cell.
  • inBounds(col: number, row: number): boolean — True inside the grid.
  • cellAt(x: number, y: number, cellSize = 1, originX = 0, originY = 0): Cell | null — The cell under a world point, given the cell size and the grid's origin; null outside.
  • isOpaque(col: number, row: number): boolean — True when the cell blocks light (outside the grid counts as opaque).
  • setOpaque(col: number, row: number, on: boolean): void — Make a cell a wall or not.
  • clearOpaque(): void — Every cell open.
  • blockFrom(grid: ReadonlyArray<ReadonlyArray<number>>, wallValue = 1): void — Set the walls from a 2D array (rows of values), treating wallValue as opaque.
  • addLight(col: number, row: number, radius: number, opts: { intensity?: number; falloff?: FogFalloff } = {}): FogLight — Add a light; returns it to move later. Intensity default 1.
  • removeLight(src: FogLight): void — Remove one light; unknown lights are ignored.
  • clearLights(): void — Remove every light.
  • compute(): void — Recompute light from every light (the max where they overlap) and extend explored. Call after anything moved.
  • lightAt(col: number, row: number): number — Brightness 0..1 at a cell; 0 outside.
  • isVisible(col: number, row: number): boolean — True when lit now.
  • isExplored(col: number, row: number): boolean — True when lit at some point (with memory).
  • state(col: number, row: number): FogState — The three-way state of a cell.
  • canSee(fromCol: number, fromRow: number, toCol: number, toRow: number, range = Infinity): boolean — Bresenham line of sight between two cells through open cells, within range cells.
  • reveal(col: number, row: number, radius: number): void — Mark everything a light at (col, row) with radius would reach as explored, without changing light.
  • revealAll(): void — Everything explored (a map reveal).
  • resetMemory(): void — Nothing explored.

Types

Cell

interface Cell

A grid cell.

  • col: number — Column.
  • row: number — Row.

FogApi

interface FogApi

game.fog.

  • create(opts: FogGridOptions): FogGrid — A fresh grid. Not scene-scoped: the game holds it.

FogFalloff

type FogFalloff = 'none' | 'linear' | 'smooth' | 'quadratic'

How a light's brightness falls with distance, as a fraction 0..1 of its radius.

FogGridOptions

interface FogGridOptions

What create takes.

  • cols: number — Columns.
  • rows: number — Rows.
  • falloff?: FogFalloff — Default falloff. Default 'smooth'.
  • memory?: boolean — Remember lit cells as 'explored' once the light moves on. Default true.

FogLight

interface FogLight

A light source on the grid. Mutate col/row to move it, then compute().

  • col: number — Cell column.
  • row: number — Cell row.
  • radius: number — Reach in cells.
  • intensity: number — Brightness at the source, 0..1.
  • falloff?: FogFalloff — This light's falloff; the grid's when omitted.

FogState

type FogState = 'unseen' | 'explored' | 'visible'

A cell's state: never lit, lit once and remembered, or lit now.