Modules / Rendering & look

light2dplugin

A darkness layer over render2d's world, lit by lights that stand on rows.

Putting it in a scene

List it before render2d, and make the render2d layer it names the last of render2d's layers, so it covers all the others.

"plugins": ["loader", "scenemanager", "player", "light2d", "render2d"],
"world": {
  "render2d": { "ground": [[32, 0], [0, 32]], "up": [0, -32], "zoom": 2, "look": [0, 0], "layers": ["ground", "things", "dark"] },
  "light2d": {
    "layer": "dark",
    "ambient": { "colour": 16777215, "level": 0.15 },
    "kinds": {
      "torch": { "colour": 16755251, "radius": 3, "intensity": 0.9, "flicker": true },
      "hero": { "colour": 16777215, "radius": 4, "intensity": 1 }
    },
    "budget": 32,
    "falloff": { "size": 128, "core": 0.2, "power": 2 },
    "flicker": { "rate": 8, "depth": 0.25 }
  }
}

Properties

Read from world.light2d.

.layer : string

The render2d layer the darkness is drawn on.

.ambient : { colour, level }

The darkness where no light reaches: colour × level in each channel, so a level of 0 is black and 1 is colour itself. colour is a number such as 0xRRGGBB. Lights add to the darkness and never brighten the world past how it is drawn.

.kinds : { [kind]: Light }

Every row of a listed kind gives light; no other row does. A row may carry its own light field, which overrides the kind's entry field by field, for what changes, such as a lantern turned down.

Light fieldMeaning
colourThe light's colour.
radiusThe distance along the ground, in world units, at which the light has fallen to nothing. In an isometric world the lit area is an ellipse.
intensityHow much of its colour it adds at its middle, 0 to 1. 0 gives no light.
flickerOptional. true or { rate?, depth? }, with anything left out taken from .flicker.

A light stands on its row's pos, so a torch on a wall lights around its flame.

.budget : number

The most lights drawn at once. The ones whose middles are nearest the middle of the canvas win, and of two equally near, the one with the lower row id.

.falloff : { size, core, power }

The shape of a light. Its brightness is full out to the fraction core of the radius, then falls to nothing at the radius, following (1 − (d − core) ÷ (1 − core)) raised to power. size is the pixel width of the picture every light is stretched from.

.flicker : { rate, depth }

A flickering light's intensity is multiplied by 1 − depth × a smooth noise between 0 and 1 that takes a new value rate times a second. Each light has its own noise, and every page shows the same flicker.

Methods

On the page, through plugins.light2d.

ambient( { colour, level } )

Sets the ambient darkness for the next draw only. Call it every frame from an actor's tick to keep a different level, such as a dark room the seat is standing in.

Properties of the plugin

lights : { id, pos, radius, colour, intensity, sprite }[]

The lights drawn last frame, with their flickered intensity.

In the guide