Skip to content

Add a lamp ​

Goal ​

Light a dark level with a lamp that stands over a thing of the world, casts shadows and flickers like a flame, from the game's settings alone.

Files you will edit ​

One of these, where the game keeps its settings:

  • src/game.ts: a game made from a template (fps, third-person), as defineGame({ lighting }).
  • settings.json: a bundle on the common Gameable player (templates/blank).

The block is the same in both. The examples below show settings.json; in src/game.ts the same object goes in defineGame:

ts
import { defineGame } from 'gameable';

export default defineGame({
  lighting: { style: 'night', lamps: [{ near: 'door', height: 2, shadows: true }] },
});

Steps ​

  1. Pick a dark style, so the lamp carries the scene, and add a lamp near a thing the world names. height is metres above it (default 1); range is how far it reaches (default 4).
json
{
  "lighting": {
    "style": "night",
    "lamps": [{ "near": "door", "height": 2, "color": "warm", "range": 5 }]
  }
}
  1. Let it cast shadows and flicker. A bulb's shadow takes 6 of the 16 shadow tiles, so a scene has room for two shadowed bulbs; a spot takes 1.
json
{
  "lighting": {
    "style": "night",
    "lamps": [
      {
        "near": "door",
        "height": 2,
        "color": "candle",
        "range": 5,
        "shadows": true,
        "flicker": true
      }
    ]
  }
}
  1. For a pool of light on one spot, use a spot aimed at another thing, or at a point:
json
{
  "lighting": {
    "style": "night",
    "lamps": [
      { "near": "door", "height": 2, "color": "candle", "shadows": true, "flicker": true },
      { "kind": "spot", "near": "table", "height": 3, "aim": "table", "cone": 25, "color": "cool" }
    ]
  }
}

Verify ​

Run the game (npm run dev for a template game; for a bundle, npm run build and the common Gameable player, examples/play/README.md). The lamp lights the place, the meshes and the characters near the door; on a computer a character walking past it throws a shadow away from it (quality: "auto" turns lamp shadows off on a phone). A near that names nothing the world has is warned about once in the console, with the things it does have. A lamp with neither at nor near stops the build: Invalid settings.lighting.lamps[0]: give it `at` (a point) or `near` (a thing).

See also ​