Skip to content

LightLayer ​

2D lights over ambient darkness.

ts
import { LightLayer, Light } from "willow";

LightLayer ​

ts
class LightLayer extends Node

Extends Node.

2D lighting overlay layer using erase blending over ambient darkness. A LightLayer is a node: add it to the tree like any other (stage.add(lights)). What is drawn before it in the tree is darkened; what is added after it, such as a UI, stays unlit.

LightLayer: constructors ​

ts
new LightLayer(ambientDarkness?: float)

Constructs a new light layer with optional ambient darkness.

LightLayer: properties ​

MemberDescription
ambient: ColorAmbient darkness tint color. Defaults to semi-transparent black.
ambientDarkness: floatDarkness strength in [0.0, 1.0]: 0.0 is unlit, 1.0 is full darkness.
ambientAlpha: floatAlias for ambientDarkness.
readonly lightCount: intNumber of active lights currently registered in the layer.

LightLayer: methods ​

MemberDescription
setAmbient(ambient: Color): voidSets the ambient color the unlit scene is tinted toward.
setAmbientDarkness(darkness: float): voidConvenience setting pure-black ambient with the given darkness in [0, 1].
setAmbientAlpha(alpha: float): voidAlias for setAmbientDarkness.
addLight(light: Light): intAdds a light source to the layer and returns its assigned ID.
removeLight(id: int): voidRemoves a light by its assigned ID or Light reference.
hasLight(id: int): booleanReturns true if a light with the given ID is active in the layer.
clearLights(): voidRemoves all light sources from the layer.
update(): voidUpdates target-following light positions.
redraw(): voidRe-evaluates light transforms and updates the layer.

LightLayer: static methods ​

MemberDescription
static create(ambientDarkness?: float): LightLayerFactory creating a light layer.

Light ​

ts
class Light

Point or textured light source placed in a LightLayer.

Light: constructors ​

ts
new Light(x?: float, y?: float, radius?: float, color?: Color, intensity?: float)

Constructs a new light with optional parameters.

Light: properties ​

MemberDescription
x: floatLight center position X in layer pixels. Defaults to 0.0.
y: floatLight center position Y in layer pixels. Defaults to 0.0.
radius: floatLight radius in pixels. Defaults to 100.0.
rotation: floatRotation in radians for textured light sources. Defaults to 0.0.
intensity: floatLight intensity in [0.0, 1.0]. Defaults to 1.0.
enabled: booleanWhether the light is enabled and contributes to the layer. Defaults to true.
color: ColorTint color of the light source. Defaults to white.
target?: NodeTarget node whose world position this light tracks. Null if untracked.
offsetX: floatHorizontal offset applied after tracking target position. Defaults to 0.0.
offsetY: floatVertical offset applied after tracking target position. Defaults to 0.0.

Light: methods ​

MemberDescription
attachTo(target: Node, offsetX?: float, offsetY?: float): voidTracks target node in world space with optional pixel offset.
detach(): voidStops tracking target node, leaving the light at its current position.