Skip to main content
Version: Phaser v4.0.0-rc.6

Light

A 2D Light.

These are created by the Phaser.GameObjects.LightsManager, available from within a scene via this.lights.

Any Game Objects with the Lighting Component, and setLighting(true),

will then be affected by these Lights.

If they have a normal map, it will be used.

If they don't, the Lights will use the default normal map, a flat surface.

They can also simply be used to represent a point light for your own purposes.

Lights cannot be added to Containers. They are designed to exist in the root of a Scene.

Constructor

new Light(x, y, radius, r, g, b, intensity, [z])

Parameters

nametypeoptionaldescription
xnumberNoThe horizontal position of the light.
ynumberNoThe vertical position of the light.
radiusnumberNoThe radius of the light.
rnumberNoThe red color of the light. A value between 0 and 1.
gnumberNoThe green color of the light. A value between 0 and 1.
bnumberNoThe blue color of the light. A value between 0 and 1.
intensitynumberNoThe intensity of the light.
znumberYesThe z position of the light. If not given, it will be set to radius * 0.1.

Scope: static

Extends

Phaser.Geom.Circle
Phaser.GameObjects.Components.Origin
Phaser.GameObjects.Components.ScrollFactor
Phaser.GameObjects.Components.Visible

Source: src/gameobjects/lights/Light.js#L13
Since: 3.0.0

Inherited Members

From Phaser.GameObjects.Components.Origin:

From Phaser.GameObjects.Components.ScrollFactor:

From Phaser.GameObjects.Components.Visible:

From Phaser.Geom.Circle:


Public Members

cameraFilter

cameraFilter: number

Description:

A bitmask that controls if this Game Object is drawn by a Camera or not.

Not usually set directly, instead call Camera.ignore, however you can

set this property directly using the Camera.id property:

Source: src/gameobjects/lights/Light.js#L114
Since: 3.0.0


color

color: Phaser.Display.RGB

Description:

The color of the light.

Source: src/gameobjects/lights/Light.js#L63
Since: 3.50.0


displayHeight

displayHeight: number

Description:

The height of this Light Game Object. This is the same as Light.diameter.

Source: src/gameobjects/lights/Light.js#L155
Since: 3.60.0


displayWidth

displayWidth: number

Description:

The width of this Light Game Object. This is the same as Light.diameter.

Source: src/gameobjects/lights/Light.js#L134
Since: 3.60.0


height

height: number

Description:

The height of this Light Game Object. This is the same as Light.diameter.

Source: src/gameobjects/lights/Light.js#L197
Since: 3.60.0


intensity

intensity: number

Description:

The intensity of the light.

Source: src/gameobjects/lights/Light.js#L72
Since: 3.50.0


renderFlags

renderFlags: number

Description:

The flags that are compared against RENDER_MASK to determine if this Game Object will render or not.

The bits are 0001 | 0010 | 0100 | 1000 set by the components Visible, Alpha, Transform and Texture respectively.

If those components are not used by your custom class then you can use this bitmask as you wish.

Source: src/gameobjects/lights/Light.js#L102
Since: 3.0.0


width

width: number

Description:

The width of this Light Game Object. This is the same as Light.diameter.

Source: src/gameobjects/lights/Light.js#L176
Since: 3.60.0


z

z: number

Description:

The z position of the light.

This affects the relief effect created by the light.

A higher value will make the light appear more raised.

Lit game objects are considered to be at z=0.

Thus, if z is larger than the radius of the light,

the light will not affect them.

Strong values are in the range of 0 to radius/2.

This is not a true position, and won't be affected by

perspective or camera position. It won't be set by setTo.

Use setZ to set it, or setZNormal to set it to a fraction

of the radius.

Source: src/gameobjects/lights/Light.js#L81
Since: 4.0.0


zNormal

zNormal: number

Description:

The z position of the light, as a fraction of the radius.

This affects the relief effect created by the light.

A higher value will make the light appear more raised.

Strong values are in the range of 0 to 0.5.

Source: src/gameobjects/lights/Light.js#L218
Since: 4.0.0


Inherited Methods

From Phaser.GameObjects.Components.Origin:

From Phaser.GameObjects.Components.ScrollFactor:

From Phaser.GameObjects.Components.Visible:

From Phaser.Geom.Circle:


Public Methods

setColor

<instance> setColor(rgb)

Description:

Set the color of the light from a single integer RGB value.

Parameters:

nametypeoptionaldescription
rgbnumberNoThe integer RGB color of the light.

Returns: Phaser.GameObjects.Light - This Light object.

Source: src/gameobjects/lights/Light.js#L256
Since: 3.0.0


setIntensity

<instance> setIntensity(intensity)

Description:

Set the intensity of the light.

Parameters:

nametypeoptionaldescription
intensitynumberNoThe intensity of the light.

Returns: Phaser.GameObjects.Light - This Light object.

Source: src/gameobjects/lights/Light.js#L275
Since: 3.0.0


setRadius

<instance> setRadius(radius)

Description:

Set the radius of the light.

Parameters:

nametypeoptionaldescription
radiusnumberNoThe radius of the light.

Returns: Phaser.GameObjects.Light - This Light object.

Source: src/gameobjects/lights/Light.js#L292
Since: 3.0.0


setZ

<instance> setZ(z)

Description:

Set the z position of the light.

Parameters:

nametypeoptionaldescription
znumberNoThe z position of the light.

Returns: Phaser.GameObjects.Light - This Light object.

Source: src/gameobjects/lights/Light.js#L309
Since: 4.0.0


setZNormal

<instance> setZNormal(z)

Description:

Set the z position of the light as a fraction of the radius.

This affects the relief effect created by the light.

A higher value will make the light appear more raised.

Strong values are in the range of 0 to 0.5.

Parameters:

nametypeoptionaldescription
znumberNoThe normalized z position of the light.

Returns: Phaser.GameObjects.Light - This Light object.

Source: src/gameobjects/lights/Light.js#L326
Since: 4.0.0


willRender

<instance> willRender(camera)

Description:

Compares the renderMask with the renderFlags to see if this Game Object will render or not.

Also checks the Game Object against the given Cameras exclusion list.

Parameters:

nametypeoptionaldescription
cameraPhaser.Cameras.Scene2D.CameraNoThe Camera to check against this Game Object.

Returns: boolean - True if the Game Object should be rendered, otherwise false.

Source: src/gameobjects/lights/Light.js#L240
Since: 3.50.0


Constants:

Public Members

RENDER_MASK

RENDER_MASK: number

Description:

The bitmask that GameObject.renderFlags is compared against to determine if the Game Object will render or not.

Source: src/gameobjects/lights/Light.js#L348