LightLayer
2D lights over ambient darkness.
ts
import { LightLayer, Light } from "willow";LightLayer
ts
class LightLayer extends NodeExtends 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
| Member | Description |
|---|---|
ambient: Color | Ambient darkness tint color. Defaults to semi-transparent black. |
ambientDarkness: float | Darkness strength in [0.0, 1.0]: 0.0 is unlit, 1.0 is full darkness. |
ambientAlpha: float | Alias for ambientDarkness. |
readonly lightCount: int | Number of active lights currently registered in the layer. |
LightLayer: methods
| Member | Description |
|---|---|
setAmbient(ambient: Color): void | Sets the ambient color the unlit scene is tinted toward. |
setAmbientDarkness(darkness: float): void | Convenience setting pure-black ambient with the given darkness in [0, 1]. |
setAmbientAlpha(alpha: float): void | Alias for setAmbientDarkness. |
addLight(light: Light): int | Adds a light source to the layer and returns its assigned ID. |
removeLight(id: int): void | Removes a light by its assigned ID or Light reference. |
hasLight(id: int): boolean | Returns true if a light with the given ID is active in the layer. |
clearLights(): void | Removes all light sources from the layer. |
update(): void | Updates target-following light positions. |
redraw(): void | Re-evaluates light transforms and updates the layer. |
LightLayer: static methods
| Member | Description |
|---|---|
static create(ambientDarkness?: float): LightLayer | Factory creating a light layer. |
Light
ts
class LightPoint 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
| Member | Description |
|---|---|
x: float | Light center position X in layer pixels. Defaults to 0.0. |
y: float | Light center position Y in layer pixels. Defaults to 0.0. |
radius: float | Light radius in pixels. Defaults to 100.0. |
rotation: float | Rotation in radians for textured light sources. Defaults to 0.0. |
intensity: float | Light intensity in [0.0, 1.0]. Defaults to 1.0. |
enabled: boolean | Whether the light is enabled and contributes to the layer. Defaults to true. |
color: Color | Tint color of the light source. Defaults to white. |
target?: Node | Target node whose world position this light tracks. Null if untracked. |
offsetX: float | Horizontal offset applied after tracking target position. Defaults to 0.0. |
offsetY: float | Vertical offset applied after tracking target position. Defaults to 0.0. |
Light: methods
| Member | Description |
|---|---|
attachTo(target: Node, offsetX?: float, offsetY?: float): void | Tracks target node in world space with optional pixel offset. |
detach(): void | Stops tracking target node, leaving the light at its current position. |