Class: LightsPlugin

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.


new LightsPlugin(scene)

Parameters:
Name Type Description
scene Phaser.Scene

The Scene that this Lights Plugin belongs to.

Since: 3.0.0
Source: src/gameobjects/lights/LightsPlugin.js (Line 12)

Extends

Members


active :boolean

Whether the Lights Manager is enabled.

Type:
  • boolean
Since: 3.0.0
Inherited From:
Default Value:
  • false
Source: src/gameobjects/lights/LightsManager.js (Line 59)

ambientColor :Phaser.Display.RGB

The ambient color.

Type:
Since: 3.50.0
Inherited From:
Source: src/gameobjects/lights/LightsManager.js (Line 50)

lights :Array.<Phaser.GameObjects.Light>

The Lights in the Scene.

Type:
Since: 3.0.0
Inherited From:
Default Value:
  • []
Source: src/gameobjects/lights/LightsManager.js (Line 40)

<readonly> maxLights :number

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
Since: 3.15.0
Inherited From:
Source: src/gameobjects/lights/LightsManager.js (Line 69)

scene :Phaser.Scene

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

Type:
Since: 3.0.0
Source: src/gameobjects/lights/LightsPlugin.js (Line 52)

systems :Phaser.Scenes.Systems

A reference to the Scene's systems.

Type:
Since: 3.0.0
Source: src/gameobjects/lights/LightsPlugin.js (Line 61)

<readonly> visibleLights :number

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

Type:
  • number
Since: 3.50.0
Inherited From:
Source: src/gameobjects/lights/LightsManager.js (Line 80)

Methods


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

Add a Light.

Parameters:
Name Type Argument 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.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/lights/LightsManager.js (Line 232)
Returns:

The Light that was added.

Type
Phaser.GameObjects.Light

boot()

Boot the Lights Plugin.

Since: 3.0.0
Source: src/gameobjects/lights/LightsPlugin.js (Line 78)

destroy()

Destroy the Lights Plugin.

Cleans up all references.

Since: 3.0.0
Overrides:
Source: src/gameobjects/lights/LightsPlugin.js (Line 92)

disable()

Disable the Lights Manager.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/lights/LightsManager.js (Line 116)
Returns:

This Lights Manager object.

Type
Phaser.GameObjects.LightsManager

enable()

Enable the Lights Manager.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/lights/LightsManager.js (Line 96)
Returns:

This Lights Manager object.

Type
Phaser.GameObjects.LightsManager

getLightCount()

Get the number of Lights managed by this Lights Manager.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/lights/LightsManager.js (Line 219)
Returns:

The number of Lights managed by this Lights Manager.

Type
number

getLights(camera)

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.

Since: 3.50.0
Inherited From:
Source: src/gameobjects/lights/LightsManager.js (Line 131)
Returns:

The culled Lights.

Type
Array.<Phaser.GameObjects.Light>

getMaxVisibleLights()

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

Since: 3.0.0
Inherited From:
Source: src/gameobjects/lights/LightsManager.js (Line 206)
Returns:

The maximum number of Lights allowed to appear at once.

Type
number

removeLight(light)

Remove a Light.

Parameters:
Name Type Description
light Phaser.GameObjects.Light

The Light to remove.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/lights/LightsManager.js (Line 263)
Returns:

This Lights Manager object.

Type
Phaser.GameObjects.LightsManager

setAmbientColor(rgb)

Set the ambient light color.

Parameters:
Name Type Description
rgb number

The integer RGB color of the ambient light.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/lights/LightsManager.js (Line 187)
Returns:

This Lights Manager object.

Type
Phaser.GameObjects.LightsManager

shutdown()

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.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/lights/LightsManager.js (Line 285)