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
| name | type | optional | description |
|---|---|---|---|
| x | number | No | The horizontal position of the light. |
| y | number | No | The vertical position of the light. |
| radius | number | No | The radius of the light. |
| r | number | No | The red color of the light. A value between 0 and 1. |
| g | number | No | The green color of the light. A value between 0 and 1. |
| b | number | No | The blue color of the light. A value between 0 and 1. |
| intensity | number | No | The intensity of the light. |
| z | number | Yes | The 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#L115
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#L156
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#L135
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#L198
Since: 3.60.0
intensity
intensity: number
Description:
The intensity of the light. This scales the overall brightness of the light effect. A value of 1 is considered normal brightness. Higher values produce a stronger, brighter 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 Light will render or not. The relevant bit is 0001, set by the Visible component. The remaining bits are unused by Light but are reserved for custom use if required.
Source: src/gameobjects/lights/Light.js#L103
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#L177
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#L82
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#L219
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:
| name | type | optional | description |
|---|---|---|---|
| rgb | number | No | The integer RGB color of the light. |
Returns: Phaser.GameObjects.Light - This Light object.
Source: src/gameobjects/lights/Light.js#L257
Since: 3.0.0
setIntensity
<instance> setIntensity(intensity)
Description:
Set the intensity of the light. This scales the overall brightness of the light effect. A value of 1 is considered normal brightness. Higher values produce a stronger, brighter light.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| intensity | number | No | The intensity (brightness multiplier) of the light. |
Returns: Phaser.GameObjects.Light - This Light object.
Source: src/gameobjects/lights/Light.js#L276
Since: 3.0.0
setRadius
<instance> setRadius(radius)
Description:
Set the radius of the light, in pixels. This defines the circular area of influence within which lit Game Objects will be affected by this light.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| radius | number | No | The radius of the light, in pixels. |
Returns: Phaser.GameObjects.Light - This Light object.
Source: src/gameobjects/lights/Light.js#L294
Since: 3.0.0
setZ
<instance> setZ(z)
Description:
Set the z position of the light. This controls the perceived height of the light above the scene, which influences the relief (normal-map shading) effect. Larger values make the light appear more elevated. Lit Game Objects are considered to be at z=0, so if z exceeds the light's radius the light will not affect them. Strong values are in the range of 0 to radius/2.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| z | number | No | The z position of the light, where 0 is at the same level as lit Game Objects. |
Returns: Phaser.GameObjects.Light - This Light object.
Source: src/gameobjects/lights/Light.js#L312
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:
| name | type | optional | description |
|---|---|---|---|
| z | number | No | The normalized z position of the light. |
Returns: Phaser.GameObjects.Light - This Light object.
Source: src/gameobjects/lights/Light.js#L333
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:
| name | type | optional | description |
|---|---|---|---|
| camera | Phaser.Cameras.Scene2D.Camera | No | The 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#L241
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.