Phaser API Documentation

  Version: 
Filter
This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . GameObjects . LightsPlugin

This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . GameObjects . LightsPlugin

A Scene plugin that provides a Phaser.GameObjects.LightsManager for the Light2D pipeline.

Available from within a Scene via this.lights.

Add Lights using the Phaser.GameObjects.LightsManager#addLight method:

// Enable the Lights Manager because it is disabled by default
this.lights.enable();

// Create a Light at [400, 300] with a radius of 200
this.lights.addLight(400, 300, 200);

For Game Objects to be affected by the Lights when rendered, you will need to set them to use the Light2D pipeline like so:

sprite.setPipeline('Light2D');

Note that you cannot use this pipeline on Graphics Game Objects or Shape Game Objects.

Constructor:

new LightsPlugin(scene)

Parameters:

name type description
scene Phaser.Scene

The Scene that this Lights Plugin belongs to.

Since: 3.0.0

Extends


Members

active: boolean
Focus
Focus

Description:

Whether the Lights Manager is enabled.

Type:
boolean
Default: false
Inherited from: Phaser.GameObjects.LightsManager#active
Since: 3.0.0
Focus
Focus
ambientColor: Phaser.Display.RGB
Focus
Focus

Description:

The ambient color.

Type:
Inherited from: Phaser.GameObjects.LightsManager#ambientColor
Since: 3.50.0
Focus
Focus
lights: Array.<Phaser.GameObjects.Light>
Focus
Focus

Description:

The Lights in the Scene.

Type:
Default: []
Inherited from: Phaser.GameObjects.LightsManager#lights
Since: 3.0.0
Focus
Focus
<readonly> maxLights: number
Focus
Focus

Description:

The maximum number of lights that a single Camera and the lights shader can process. Change this via the maxLights property in your game config, as it cannot be changed at runtime.

Type:
number
Inherited from: Phaser.GameObjects.LightsManager#maxLights
Since: 3.15.0
Focus
Focus
scene: Phaser.Scene
Focus
Focus

Description:

A reference to the Scene that this Lights Plugin belongs to.

Type:
Since: 3.0.0
Focus
Focus

Description:

A reference to the Scene's systems.

Type:
Since: 3.0.0
Focus
Focus
<readonly> visibleLights: number
Focus
Focus

Description:

The number of lights that the LightPipeline processed in the previous frame.

Type:
number
Inherited from: Phaser.GameObjects.LightsManager#visibleLights
Since: 3.50.0
Focus
Focus

Methods

addLight([x], [y], [radius], [rgb], [intensity])
Focus
Focus

Description:

Add a Light.

Parameters:

name type arguments Default description
x number <optional> 0

The horizontal position of the Light.

y number <optional> 0

The vertical position of the Light.

radius number <optional> 100

The radius of the Light.

rgb number <optional> 0xffffff

The integer RGB color of the light.

intensity number <optional> 1

The intensity of the Light.

Returns:
Description:

The Light that was added.

Inherited from: Phaser.GameObjects.LightsManager#addLight
Examples:
Since: 3.0.0
Focus
Focus
boot()
Focus
Focus

Description:

Boot the Lights Plugin.

Examples:
Since: 3.0.0
Focus
Focus
destroy()
Focus
Focus

Description:

Destroy the Lights Plugin.

Cleans up all references.

Overrides: Phaser.GameObjects.LightsManager#destroy
Examples:
Since: 3.0.0
Focus
Focus
disable()
Focus
Focus

Description:

Disable the Lights Manager.

Returns:
Description:

This Lights Manager object.

Inherited from: Phaser.GameObjects.LightsManager#disable
Examples:
Since: 3.0.0
Focus
Focus
enable()
Focus
Focus

Description:

Enable the Lights Manager.

Returns:
Description:

This Lights Manager object.

Inherited from: Phaser.GameObjects.LightsManager#enable
Examples:
Since: 3.0.0
Focus
Focus
getLightCount()
Focus
Focus

Description:

Get the number of Lights managed by this Lights Manager.

Returns:
Description:

The number of Lights managed by this Lights Manager.

Type:
  • number
Inherited from: Phaser.GameObjects.LightsManager#getLightCount
Examples:
Since: 3.0.0
Focus
Focus
getLights(camera)
Focus
Focus

Description:

Get all lights that can be seen by the given Camera.

It will automatically cull lights that are outside the world view of the Camera.

If more lights are returned than supported by the pipeline, the lights are then culled based on the distance from the center of the camera. Only those closest are rendered.

Parameters:

name type description
camera Phaser.Cameras.Scene2D.Camera

The Camera to cull Lights for.

Returns:
Description:

The culled Lights.

Type:
Inherited from: Phaser.GameObjects.LightsManager#getLights
Examples:
Since: 3.50.0
Focus
Focus
getMaxVisibleLights()
Focus
Focus

Description:

Returns the maximum number of Lights allowed to appear at once.

Returns:
Description:

The maximum number of Lights allowed to appear at once.

Type:
  • number
Inherited from: Phaser.GameObjects.LightsManager#getMaxVisibleLights
Examples:
Since: 3.0.0
Focus
Focus
removeLight(light)
Focus
Focus

Description:

Remove a Light.

Parameters:

name type description
light Phaser.GameObjects.Light

The Light to remove.

Returns:
Description:

This Lights Manager object.

Inherited from: Phaser.GameObjects.LightsManager#removeLight
Examples:
Since: 3.0.0
Focus
Focus
setAmbientColor(rgb)
Focus
Focus

Description:

Set the ambient light color.

Parameters:

name type description
rgb number

The integer RGB color of the ambient light.

Returns:
Description:

This Lights Manager object.

Inherited from: Phaser.GameObjects.LightsManager#setAmbientColor
Examples:
Since: 3.0.0
Focus
Focus
shutdown()
Focus
Focus

Description:

Shut down the Lights Manager.

Recycles all active Lights into the Light pool, resets ambient light color and clears the lists of Lights and culled Lights.

Inherited from: Phaser.GameObjects.LightsManager#shutdown
Examples:
Since: 3.0.0
Focus
Focus