Skip to main content
BuildOfficialCertifiedReviewed Dec 4, 2026

lighting

v1.0.0New

Unsigned, install at your own risk

Unverified

This skill has no cryptographic signature attached. We can't verify the contents match what the publisher intended.

Install this skill

No account required. Pick your tool, then copy.

Run in your terminal. It detects your AI tool.

npx @skills-hub-ai/cli install phaser-lighting

What this does: Phaser 4 dynamic lighting, which is WebGL only: the Scene's LightsManager (this.lights.enable, addLight, addConeLight, setAmbientColor, removeLight, render.maxLights), setLighting(true) on Sprites, Images, Text, TileSprites, tilemap layers, particles, Graphics and Shapes, normal maps (load.image with [diffuse, normal], setDataSource), self-shadowing (setSelfShadow, render.selfShadow), cone lights (setCone, setConeRotation, setConeAngles), the PointLight Game Object and the ImageLight filter. Use when adding lights, a torch, lantern, flashlight, spotlight, vision cone, darkness or a day/night mood, glowing lamps, muzzle flashes, or bumpy normal-mapped sprites and tiles. Replaces v3's setPipeline('Light2D'), which doesn't exist in v4. Lit objects render black unless this.lights.enable() is called. Triggers on: light, lights, lighting, normal map, setLighting, Light2D, ambient light, cone light, spotlight, flashlight, torch, lantern, PointLight, pointlight, self shadow, ImageLight.

Or get the file:
Browse all CLI commands →
Manual setup by platform

Claude Code

~/.claude/skills/phaser-lighting/SKILL.md

Setup guide →
0Save

Instructions

Lighting

Per-pixel lights in WebGL. A Scene's lights shade every Game Object which has lighting turned on, using its normal map if it has one. This skill also covers the PointLight Game Object and the ImageLight filter, which are separate from the lights.

Source: src/gameobjects/lights/LightsManager.js, src/gameobjects/lights/Light.js, src/gameobjects/components/Lighting.js, src/gameobjects/pointlight/PointLight.js, src/filters/ImageLight.js, docs/Phaser 4 Cone Lights/. Related: loading-assets, filters-and-postfx, tilemaps, particles, phaser4-core.

Quick start

class Dungeon extends Phaser.Scene
{
    preload ()
    {
        //  The second URL is the normal map
        this.load.image('wall', [ 'assets/wall.png', 'assets/wall_n.png' ]);
    }

    create ()
    {
        const { width, height } = this.scale;
        const wall = this.add.image(width / 2, height / 2, 'wall');

        //  Lighting is WebGL only. In Canvas, objects are drawn unlit.
        if (this.renderer.type !== Phaser.WEBGL)
        {
            return;
        }

        //  Without enable(), objects with lighting on render black
        this.lights.enable().setAmbientColor(0x202020);

        wall.setLighting(true);

        const torch = this.lights.addLight(width / 2, height / 2, 250, 0xffaa66, 2);

        this.input.on(Phaser.Input.Events.POINTER_MOVE, (pointer) =>
        {
            torch.setPosition(pointer.worldX, pointer.worldY);
        });
    }
}

Two things are needed: this.lights.enable() once per Scene, and setLighting(true) on each object to light. A normal map is optional.

The LightsManager: this.lights

Every Scene has one (the LightsPlugin).

MemberNotes
enable() / disable()Return this. active is the flag.
addLight(x = 0, y = 0, radius = 128, rgb = 0xffffff, intensity = 1, z = radius * 0.1)Returns a Phaser.GameObjects.Light.
addConeLight(x, y, radius, rgb, intensity, rotation = 0, innerAngle = Math.PI / 4, outerAngle = innerAngle, z)A Light limited to a cone (4.2).
setAmbientColor(0x202020)Added to every lit pixel. Takes an integer, not a string. The default is 0.1 grey, about 0x1a1a1a.
removeLight(light)Removes it. Lights aren't Game Objects, so there's no light.destroy().
lightsThe array of Lights. getLightCount() returns its length.
maxLights, visibleLightsThe limit, and how many were drawn by the last Camera.
addPointLight(...)Makes a PointLight Game Object, not a Light. See below.

The lights are removed when the Scene shuts down.

How many lights

  • Set the limit in the game config: render: { maxLights: 20 }. The default is 10. It is compiled into the shaders, so don't raise this.lights.maxLights at runtime.
  • Each Camera skips Lights whose circle (x, y, radius) is outside its view. If more than maxLights are left, it keeps those nearest the centre of the Camera.
  • Every visible light costs shader time on every lit pixel. Prefer a raised ambient colour to many large, dim lights.

Lights

A Light is not a Game Object: it isn't on the display list and has no depth, alpha, or destroy. It extends Phaser.Geom.Circle, with these added:

MemberNotes
x, y, radius, setPosition(x, y), setRadius(r)World position. The light fades to nothing at radius.
color, setColor(0xffffff)color is an RGB object of floats from 0 to 1.
intensity, setIntensity(n)Brightness multiplier. Values above 1 are fine.
z, setZ(z), setZNormal(n)Height above the surface. The default is radius * 0.1. setZNormal sets it as a multiple of the radius. A higher light shows less of the normal map. The height counts towards the distance, so a light with z at or above its radius lights nothing.
setScrollFactor(x, y)Default 1. Use 0 to pin a light to the Camera.
visible, setVisible(bool)A hidden light is switched off.

All of these can be tweened, for a flicker or a pulse: this.tweens.add({ targets: light, intensity: 3, yoyo: true, repeat: -1 }).

What can be lit

setLighting(true) comes from the Lighting component, which these have: Image, Sprite (and the Arcade and Matter versions), Stamp, RenderTexture, TileSprite, Text, BitmapText, DynamicBitmapText, Blitter, Video, ParticleEmitter (it lights every particle), Mesh2D, SpriteGPULayer, TilemapLayer, TilemapGPULayer, Graphics and every Shape.

Not lit: Container and Layer (light their children instead), NineSlice, Rope, Shader, Gradient, the Noise objects and PointLight.

  • An object without a normal map uses a flat one. Lights then shade it by distance only.
  • Graphics and Shapes always use a flat normal and can't self-shadow. Since 4.3, stroked triangles in a lit Graphics are lit too.
  • A tilemap layer uses the normal map of its tileset image: load the tileset with this.load.image('tiles', [ 'tiles.png', 'tiles_n.png' ]), then layer.setLighting(true).
  • lighting is the flag. setLighting(false) returns the object to normal drawing.

Normal maps

Pass the normal map as the second URL, or as normalMap in a config object. Image, spritesheet, atlas, multiatlas (a normalMap entry in each texture of the JSON), unityAtlas, aseprite and bitmapFont files support this. See loading-assets.

this.load.image('rock', [ 'rock.png', 'rock_n.png' ]);
this.load.spritesheet('hero', [ 'hero.png', 'hero_n.png' ], { frameWidth: 32, frameHeight: 48 });
this.load.atlas('props', [ 'props.png', 'props_n.png' ], 'props.json');
this.load.image({ key: 'door', url: 'door.png', normalMap: 'door_n.png' });

To attach a normal map loaded under its own key:

const rock = this.textures.get('rock');
rock.setDataSource(this.textures.get('rock_n').getSourceImage());
  • The normal map must have the same size and layout as the texture: every frame of the texture uses the same area of the normal map.
  • The normal map turns with the object, and with its parent Containers.
  • Lit objects don't use multi-texture batching: each change of texture is a new draw call. Pack lit art into one atlas, with one normal map.

Self-shadowing

Self-shadows darken the parts of a texture which its own bumps would shade, based on the brightness of the texture. They only work on lit, textured objects, not on Graphics or Shapes.

//  The default for every lit object, in the game config
const config = { type: Phaser.WEBGL, render: { selfShadow: true } };

//  For one object: enabled, penumbra (0.5), diffuseFlatThreshold (1/3)
sprite.setSelfShadow(true, 0.5, 1 / 3);

//  Go back to the game config value
sprite.setSelfShadow(null);
  • selfShadow is { enabled, penumbra, diffuseFlatThreshold }. enabled: null means "use render.selfShadow", which defaults to false. Arguments left undefined are left unchanged.
  • A lower penumbra gives a sharper but more jagged shadow edge. diffuseFlatThreshold (0 to 1) is the texture brightness above which the surface counts as flat.
  • 4.3: each object has its own settings. Before 4.3 they were shared, so setSelfShadow on one object changed every object of its class.
  • 4.3: the penumbra and the threshold were swapped in the shader before 4.3. To keep the look of an older game, use setSelfShadow(true, 1 / 3, 0.5).

Cone lights

A cone light is a normal Light limited to a cone: a flashlight, a headlight, a guard's vision cone. It costs about the same as any light, and needs no mask or second Camera.

//  In create()
this.player = this.add.sprite(200, 300, 'player').setLighting(true);

this.beam = this.lights.addConeLight(
    this.player.x, this.player.y, 360, 0xffd28a, 2.5,
    this.player.rotation,         //  direction in radians
    Phaser.Math.DegToRad(35),     //  inner angle: full light
    Phaser.Math.DegToRad(75)      //  outer angle: fades out between inner and outer
);

//  In update()
this.beam.setPosition(this.player.x, this.player.y);
this.beam.setConeRotation(this.player.rotation);
  • rotation 0 points right, Math.PI / 2 points down, -Math.PI / 2 points up. If your art faces up, use player.rotation - Math.PI / 2.
  • The angles are the full width of the cone, not half of it.
  • Leave out the outer angle, or make it equal to the inner one, for a hard edge. Angles are clamped from 0 to Math.PI * 2, and an outer angle smaller than the inner one is raised to it.
  • Any Light can become a cone, and back: light.setCone(rotation, inner, outer), setConeRotation(r), setConeAngles(inner, outer), disableCone(). The properties are coneEnabled, coneRotation, coneInnerAngle and coneOuterAngle.
  • Culling still uses the light's whole circle, so a small radius keeps cones cheap.
  • Full guide: docs/Phaser 4 Cone Lights/Phaser 4 Cone Lights.md.

PointLight: a glow, not a light

const glow = this.add.pointlight(300, 200, 0xff8800, 64, 0.8, 0.1);  //  color, radius, intensity, attenuation
  • A Game Object which draws a soft radial glow. It doesn't light other objects, ignores normal maps, doesn't need this.lights.enable(), and doesn't count towards maxLights. It is very cheap: use it for torches, sparks and muzzle flashes.
  • The arguments are in a different order from addLight: colour comes before radius.
  • color is a Phaser.Display.Color: change it with glow.color.setTo(255, 0, 0). radius, intensity and attenuation can be tweened. Its origin is always 0.5.
  • For many of them, keep them next to each other on the display list, or in a Layer, so they batch.
  • It draws nothing in Canvas.

To light other objects, use a Light (addLight or addConeLight).

ImageLight filter

Image-based lighting: it reflects an environment map (a 360-degree panorama) off a surface described by a normal map, like a shiny orb or a metal sign. It is a filter, so it needs enableFilters(), and it has nothing to do with this.lights.

const orb = this.add.image(300, 200, 'orb');

orb.enableFilters();  //  WebGL only: guard as in the Quick start

const shine = orb.filters.internal.addImageLight({
    environmentMap: 'sky',      //  texture key of the panorama
    normalMap: 'orb_n',         //  texture key of a normal map which matches the object
    bulge: 0.1,                 //  stops flat areas reflecting one flat colour
    colorFactor: [ 1, 1, 1 ],   //  above 1 brightens, in place of HDR
    modelRotationSource: orb    //  or a function returning radians, or use modelRotation
});
  • Always pass a config object. Give the maps as texture keys (strings). The defaults are '__WHITE' and the flat '__NORMAL'.
  • shine.setNormalMapFromGameObject(obj) uses the normal map which was loaded with the object's texture. setEnvironmentMap(key) and setNormalMap(key) swap the maps.
  • viewMatrix (a Matrix4) turns the environment.
  • A sharp panorama gives a mirror finish. For a rougher surface, blur it with the PanoramaBlur filter once, into a DynamicTexture, and use that: PanoramaBlur is far too slow to run every frame. The NormalTools filter can rotate or adjust a normal map. See filters-and-postfx.

Gotchas

  • Lit objects are black without this.lights.enable(). setLighting(true) alone switches the object to the lighting shader, which then has no lights and no ambient colour.
  • The default ambient colour is very dark (0.1 grey). Anything outside a light's radius is nearly black. Set it with setAmbientColor.
  • Canvas has no lighting. Lit objects are drawn unlit, PointLights draw nothing, and obj.filters (for ImageLight) stays null. Phaser.AUTO can fall back to Canvas, so guard on this.renderer.type === Phaser.WEBGL.
  • The light count is fixed by the config. render.maxLights (default 10) is compiled into the shaders.
  • Lights are in world space. They scroll with the world, like Game Objects, unless you give them a scroll factor of 0. They are not children of Containers, so move them yourself, in update.
  • Lighting breaks batches. It changes the shader and turns off multi-texturing, so lit objects only batch while they share a texture and normal map. Keep lit objects with the same texture next to each other on the display list.
  • v3 habits: there is no Light2D pipeline and no setPipeline. Use setLighting(true). Light height is now the explicit z, not worked out from the game size.
This skill doesn’t include stateful context yet, instructions only. Learn about stateful skills.

Security

Loading security scan...

Reviews (0)

Frequently asked questions about lighting

What does the lighting skill do?

Phaser 4 dynamic lighting, which is WebGL only: the Scene's LightsManager (this.lights.enable, addLight, addConeLight, setAmbientColor, removeLight, render.maxLights), setLighting(true) on Sprites, Images, Text, TileSprites, tilemap layers, particles, Graphics and Shapes, normal maps (load.image with [diffuse, normal], setDataSource), self-shadowing (setSelfShadow, render.selfShadow), cone lights (setCone, setConeRotation, setConeAngles), the PointLight Game Object and the ImageLight filter. Use when adding lights, a torch, lantern, flashlight, spotlight, vision cone, darkness or a day/night mood, glowing lamps, muzzle flashes, or bumpy normal-mapped sprites and tiles. Replaces v3's setPipeline('Light2D'), which doesn't exist in v4. Lit objects render black unless this.lights.enable() is called. Triggers on: light, lights, lighting, normal map, setLighting, Light2D, ambient light, cone light, spotlight, flashlight, torch, lantern, PointLight, pointlight, self shadow, ImageLight. It's a reusable SKILL.md instruction set that loads into your AI coding assistant on demand, no prompt engineering, no copy-pasting every session.

How do I install the lighting skill?

Run `npx @skills-hub-ai/cli install phaser-lighting` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/phaser-lighting/ for Claude Code or ~/.cursor/skills/ for Cursor with --target cursor) and adds it to your project's .skills.json lockfile.

Which AI tools does lighting work with?

lighting runs in Claude Code. It follows the open Agent Skills standard (SKILL.md), so the same skill works in every supported tool without modification.

Is the lighting skill free?

Yes. Every skill on skills-hub.ai is free and open-source. There are no premium tiers, paywalls, or usage limits. You only pay for whatever AI assistant you're already using.

How do I use lighting after installing it?

In Claude Code, type `/phaser-lighting` (or whatever slash command the skill registers) and the AI follows the skill's instructions immediately. You can also reference it by name in natural language, your AI loads the skill into context when relevant.

Can I share the lighting skill with my team?

Yes. Commit your project's .skills.json lockfile and teammates run `npx @skills-hub-ai/cli install` (no args) to install every skill at the exact version you pinned. Organization-scoped installs work via skills-hub.ai organizations.

Badge for your README

Show that this skill is on Skills Hub. The badge links back to this page and shows the live install count.

Install on Skills Hub badge preview
Markdown
[![Install on Skills Hub](https://skills-hub.ai/api/badges/skill/phaser-lighting)](https://skills-hub.ai/skills/phaser-lighting)
HTML
<a href="https://skills-hub.ai/skills/phaser-lighting"><img src="https://skills-hub.ai/api/badges/skill/phaser-lighting" alt="Install on Skills Hub"></a>

More options in the badge docs.