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#L155
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
coneEnabled
coneEnabled: boolean
Description:
Whether this Light is restricted to a cone.
Source: src/gameobjects/lights/Light.js#L103
Since: 4.2.0
coneInnerAngle
coneInnerAngle: number
Description:
The inner cone angle, in radians. Fragments inside this angle receive full light.
Source: src/gameobjects/lights/Light.js#L123
Since: 4.2.0
coneOuterAngle
coneOuterAngle: number
Description:
The outer cone angle, in radians. Fragments outside this angle receive no light.
Source: src/gameobjects/lights/Light.js#L133
Since: 4.2.0
coneRotation
coneRotation: number
Description:
The cone direction, in radians, in world space.
Source: src/gameobjects/lights/Light.js#L113
Since: 4.2.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#L196
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#L175
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#L238
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#L143
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#L217
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#L259
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
disableCone
<instance> disableCone()
Description:
Disable cone limiting and make this Light omnidirectional again.
Returns: Phaser.GameObjects.Light - This Light object.
Source: src/gameobjects/lights/Light.js#L475
Since: 4.2.0
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#L297
Since: 3.0.0
setCone
<instance> setCone(rotation, innerAngle, [outerAngle])
Description:
Restrict this Light to a cone, suitable for flashlights, lanterns and other focal lights.
The rotation is in radians, where 0 points to the right in world space. The innerAngle is the fully-lit cone width. The outerAngle is the wider falloff cone width; if omitted, the cone has a hard edge. Both angles are full cone widths, not half-angles.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| rotation | number | No | The direction of the cone, in radians. | |
| innerAngle | number | No | The fully-lit cone width, in radians. | |
| outerAngle | number | Yes | "innerAngle" | The outer falloff cone width, in radians. |
Returns: Phaser.GameObjects.Light - This Light object.
Source: src/gameobjects/lights/Light.js#L393
Since: 4.2.0
setConeAngles
<instance> setConeAngles(innerAngle, [outerAngle])
Description:
Set the inner and outer cone angles, in radians.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| innerAngle | number | No | The fully-lit cone width, in radians. | |
| outerAngle | number | Yes | "innerAngle" | The outer falloff cone width, in radians. |
Returns: Phaser.GameObjects.Light - This Light object.
Source: src/gameobjects/lights/Light.js#L446
Since: 4.2.0
setConeRotation
<instance> setConeRotation(rotation)
Description:
Set the direction of this Light cone, in radians.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| rotation | number | No | The direction of the cone, in radians. |
Returns: Phaser.GameObjects.Light - This Light object.
Source: src/gameobjects/lights/Light.js#L429
Since: 4.2.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#L316
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#L334
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#L352
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#L373
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#L281
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.