Skip to content

1681-engine / index / LightLayer

Class: LightLayer ​

Defined in: src/light/LightLayer.ts:65

Smooth darkness with lights cut out of it, for art that is not pixel art (the pixel module has its own dithered Darkness). The dark is a screen-sized texture: each light erases a soft hole in it, and lays its colour over what shows through. It sits on the screen layer, over the world and under the HUD you add after it.

ts
const night = new LightLayer(stage, { darkness: 0.9 });
const torch = night.add({ x: 100, y: 80, radius: 90, color: 0xffb060, flicker: 0.08 });
// each frame: torch.x = hero.x; night.update(now);

Constructors ​

Constructor ​

ts
new LightLayer(stage, options?): LightLayer;

Defined in: src/light/LightLayer.ts:80

Parameters ​

ParameterType
stageStage
optionsLightLayerOptions

Returns ​

LightLayer

Methods ​

add() ​

ts
add(light): Light;

Defined in: src/light/LightLayer.ts:98

Parameters ​

ParameterType
lightLight

Returns ​

Light


clear() ​

ts
clear(): void;

Defined in: src/light/LightLayer.ts:107

Returns ​

void


destroy() ​

ts
destroy(): void;

Defined in: src/light/LightLayer.ts:155

Returns ​

void


remove() ​

ts
remove(light): void;

Defined in: src/light/LightLayer.ts:103

Parameters ​

ParameterType
lightLight

Returns ​

void


setAmbient() ​

ts
setAmbient(color, darkness): void;

Defined in: src/light/LightLayer.ts:112

Changes the dark: its colour and how dark (a day/night cycle eases these).

Parameters ​

ParameterType
colornumber
darknessnumber

Returns ​

void


update() ​

ts
update(now?): void;

Defined in: src/light/LightLayer.ts:118

Redraws the dark with this frame's lights. Call once a frame, after the camera moved.

Parameters ​

ParameterType
nownumber

Returns ​

void

Released under the MIT License.