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');

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 11)

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 77)

ambientColor :Object

The ambient color.

Type:
  • Object
Since: 3.0.0
Inherited From:
Source: src/gameobjects/lights/LightsManager.js (Line 68)

culledLights :Array.<Phaser.GameObjects.Light>

Lights that have been culled from a Camera's viewport.

Lights in this list will not be rendered.

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

lightPool :Array.<Phaser.GameObjects.Light>

The pool of Lights.

Used to recycle removed Lights for a more efficient use of memory.

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

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 46)

<readonly> maxLights :integer

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

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 49)

systems :Phaser.Scenes.Systems

A reference to the Scene's systems.

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

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 255)
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 75)

cull(camera)

Cull any Lights that aren't visible to the given Camera.

Culling Lights improves performance by ensuring that only Lights within a Camera's viewport are rendered.

Parameters:
Name Type Description
camera Phaser.Cameras.Scene2D.Camera

The Camera to cull Lights for.

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

The culled Lights.

Type
Array.<Phaser.GameObjects.Light>

destroy()

Destroy the Lights Plugin.

Cleans up all references.

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

disable()

Disable the Lights Manager.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/lights/LightsManager.js (Line 119)
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 99)
Returns:

This Lights Manager object.

Type
Phaser.GameObjects.LightsManager

forEachLight(callback)

Iterate over each Light with a callback.

Parameters:
Name Type Description
callback LightForEach

The callback that is called with each Light.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/lights/LightsManager.js (Line 180)
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 242)
Returns:

The number of Lights managed by this Lights Manager.

Type
integer

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 229)
Returns:

The maximum number of Lights allowed to appear at once.

Type
integer

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 298)
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 208)
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 321)