This file implements a lightweight fog-of-war system for the isometric map in cell auto isometric.
It provides:
FogExplorerComponent— a marker component added to actors that should clear fog.FOW— an ExcaliburSystemthat scans fog tiles and clears them when an explorer overlaps.
- Extends Excalibur
Component. - Contains a single flag:
isActive. - Used to identify entities that can reveal fog.
- Extends Excalibur
System. - Queries entities that contain:
FogExplorerComponentTransformComponentBodyComponent
- Maintains an optional reference to the current
ExIsoMetricMap. - Uses a tick interval to reduce processing frequency.
- The system is created with a reference to the Excalibur
World. registerMap(map)attaches the upper isometric map used for fog.- During
update(), the system:- returns early when no map is registered.
- increments a global tick counter and only processes every
TIK_INTERVALupdates. - iterates over each explorer entity in the query.
- fetches the explorer's
graphics.boundsand compares it against each tile's stored bounds. - if an explorer overlaps a fogged tile, and the tile is not already dirty:
- sets
tile.data.fogtofalse - marks the map as dirty by calling
this._map.addTag("dirty") - pushes the tile onto
this._map.dirtyTiles
- sets
FOW depends on the upper map having these properties:
tiles: the isometric tiles to scan.- each tile must have:
tile.data.get("bounds")— a rectangle withtop,bottom,left,righttile.data.get("fog")— a boolean indicating if the tile is currently covered.
dirtyTiles: an array of tiles that need redraw.addTag("dirty")triggers the map redraw logic inlevelGen.ts.
This contract is implemented by the ExIsoMetricMap type from src/Lib/levelGen.ts.
The active fog explorer is created in src/Actors/walkingPlayer.ts:
FowChildActoris a transparent child actor with aFogExplorerComponent(true).- It is added as a child of
WalkingPlayer.
Typical usage:
- Add the system to the world:
const fogSystem = new FOW(world); world.addSystem(fogSystem);
- Register the upper map once it is created:
fogSystem.registerMap(upperMap);
TIK_INTERVALis currently5. This means the fog check only runs every 5 frames.- The implementation uses a global
TIKcounter shared across the file. - If
tile.data.get("fog")is alreadyfalse, the tile is skipped. - If
this._map.dirtyTilesis undefined, fog clearing is skipped for safety.
- Replace the global
TIKcounter with per-system state. - Use a spatial index instead of brute-forcing all tiles.
- Store
explorerBoundsand tile bounds in a consistent coordinate space. - Avoid scanning all map tiles each update for performance on larger maps.
src/Actors/walkingPlayer.ts— definesFowChildActorand attaches the explorer component.src/Lib/levelGen.ts— builds the isometric map and handles tile redraw via dirty updates.
