Interface DestructibleTerrainOptions

Construction options for DestructibleTerrain.

interface DestructibleTerrainOptions {
    autoSimulate?: boolean;
    chunkSize?: number;
    height: number;
    materials?: readonly Material[];
    onDebrisCreated?: ((event: DebrisCreatedEvent) => void);
    pixelsPerMeter?: number;
    scene: Scene;
    simplificationEpsilon?: number;
    width: number;
    worldId?: {
        __brand: "WorldId";
    };
    x?: number;
    y?: number;
}

Properties

autoSimulate?: boolean

When true, update() runs one cellular-automaton tick before the renderer/physics flush. Default false for back-compat — v1.x users get the same behavior they had. Enable when any registered material has simulation: 'sand' (or other future fluid kinds) so the bitmap is stepped automatically each frame.

The simulation tick is O(width × height) per call. For very large bitmaps without fluid materials in flight, leaving this false and calling terrain.simStep() manually only when you know fluid pixels exist is a worthwhile optimization.

chunkSize?: number

Edge length of each chunk in pixels. Default 64.

height: number

World height in pixels. Must be divisible by chunkSize.

materials?: readonly Material[]

Materials to register up-front.

onDebrisCreated?: ((event: DebrisCreatedEvent) => void)

Called once per dynamic debris body the queue creates during a flush. The handler receives the body id, the bitmap-space outer contour the body was built from, and the material used for its physical properties. Use this to spawn a sprite or graphics for the debris.

Body lifetime is the caller's responsibility — debris bodies are not destroyed by the terrain itself.

pixelsPerMeter?: number

Pixels per Box2D meter. Defaults to 32 (Phaser Box2D convention).

scene: Scene
simplificationEpsilon?: number

Douglas-Peucker simplification epsilon for collider contours. Default 1.

width: number

World width in pixels. Must be divisible by chunkSize.

worldId?: {
    __brand: "WorldId";
}

Box2D world to attach colliders to. Optional — terrain works purely visually if you don't need physics. When provided, the terrain manages chunk collider lifecycle internally; carve / deposit calls dirty chunks and the next update() flushes the deferred queue.

x?: number

Where to place the terrain's top-left in scene coordinates. Defaults to (0, 0).

y?: number

Scene Y offset.