Class: Light

Phaser.GameObjects. Light

A 2D point light.

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

Any Game Objects using the Light2D pipeline will then be affected by these Lights as long as they have a normal map.

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


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

Parameters:
Name Type Description
x number

The horizontal position of the light.

y number

The vertical position of the light.

radius number

The radius of the light.

r number

The red color of the light. A value between 0 and 1.

g number

The green color of the light. A value between 0 and 1.

b number

The blue color of the light. A value between 0 and 1.

intensity number

The intensity of the light.

Since: 3.0.0
Source: src/gameobjects/lights/Light.js (Line 13)

Extends

Members


<static, constant> RENDER_MASK :number

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

Type:
  • number
Source: src/gameobjects/lights/Light.js (Line 174)

bottom :number

The bottom position of the Circle.

Type:
  • number
Since: 3.0.0
Inherited From:
Source: src/geom/circle/Circle.js (Line 346)

color :Phaser.Display.RGB

The color of the light.

Type:
Since: 3.50.0
Source: src/gameobjects/lights/Light.js (Line 55)

diameter :number

The diameter of the Circle.

Type:
  • number
Since: 3.0.0
Inherited From:
Source: src/geom/circle/Circle.js (Line 261)

intensity :number

The intensity of the light.

Type:
  • number
Since: 3.50.0
Source: src/gameobjects/lights/Light.js (Line 64)

left :number

The left position of the Circle.

Type:
  • number
Since: 3.0.0
Inherited From:
Source: src/geom/circle/Circle.js (Line 283)

radius :number

The radius of the Circle.

Type:
  • number
Since: 3.0.0
Inherited From:
Source: src/geom/circle/Circle.js (Line 239)

The right position of the Circle.

Type:
  • number
Since: 3.0.0
Inherited From:
Source: src/geom/circle/Circle.js (Line 304)

scrollFactorX :number

The horizontal scroll factor of this Game Object.

The scroll factor controls the influence of the movement of a Camera upon this Game Object.

When a camera scrolls it will change the location at which this Game Object is rendered on-screen. It does not change the Game Objects actual position values.

A value of 1 means it will move exactly in sync with a camera. A value of 0 means it will not move at all, even if the camera moves. Other values control the degree to which the camera movement is mapped to this Game Object.

Please be aware that scroll factor values other than 1 are not taken in to consideration when calculating physics collisions. Bodies always collide based on their world position, but changing the scroll factor is a visual adjustment to where the textures are rendered, which can offset them from physics bodies if not accounted for in your code.

Type:
  • number
Since: 3.0.0
Inherited From:
Default Value:
  • 1
Source: src/gameobjects/components/ScrollFactor.js (Line 16)

scrollFactorY :number

The vertical scroll factor of this Game Object.

The scroll factor controls the influence of the movement of a Camera upon this Game Object.

When a camera scrolls it will change the location at which this Game Object is rendered on-screen. It does not change the Game Objects actual position values.

A value of 1 means it will move exactly in sync with a camera. A value of 0 means it will not move at all, even if the camera moves. Other values control the degree to which the camera movement is mapped to this Game Object.

Please be aware that scroll factor values other than 1 are not taken in to consideration when calculating physics collisions. Bodies always collide based on their world position, but changing the scroll factor is a visual adjustment to where the textures are rendered, which can offset them from physics bodies if not accounted for in your code.

Type:
  • number
Since: 3.0.0
Inherited From:
Default Value:
  • 1
Source: src/gameobjects/components/ScrollFactor.js (Line 40)

top :number

The top position of the Circle.

Type:
  • number
Since: 3.0.0
Inherited From:
Source: src/geom/circle/Circle.js (Line 325)

<readonly> type :number

The geometry constant type of this object: GEOM_CONST.CIRCLE. Used for fast type comparisons.

Type:
  • number
Since: 3.19.0
Inherited From:
Source: src/geom/circle/Circle.js (Line 41)

visible :boolean

The visible state of the Game Object.

An invisible Game Object will skip rendering, but will still process update logic.

Type:
  • boolean
Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Visible.js (Line 31)

x :number

The x position of the center of the circle.

Type:
  • number
Since: 3.0.0
Inherited From:
Default Value:
  • 0
Source: src/geom/circle/Circle.js (Line 52)

y :number

The y position of the center of the circle.

Type:
  • number
Since: 3.0.0
Inherited From:
Default Value:
  • 0
Source: src/geom/circle/Circle.js (Line 62)

Methods


contains(x, y)

Check to see if the Circle contains the given x / y coordinates.

Parameters:
Name Type Description
x number

The x coordinate to check within the circle.

y number

The y coordinate to check within the circle.

Since: 3.0.0
Inherited From:
Source: src/geom/circle/Circle.js (Line 93)
Returns:

True if the coordinates are within the circle, otherwise false.

Type
boolean

getPoint(position [, out])

Returns a Point object containing the coordinates of a point on the circumference of the Circle based on the given angle normalized to the range 0 to 1. I.e. a value of 0.5 will give the point at 180 degrees around the circle.

Parameters:
Name Type Argument Description
position number

A value between 0 and 1, where 0 equals 0 degrees, 0.5 equals 180 degrees and 1 equals 360 around the circle.

out Phaser.Geom.Point | object <optional>

An object to store the return values in. If not given a Point object will be created.

Since: 3.0.0
Inherited From:
Source: src/geom/circle/Circle.js (Line 109)
Returns:

A Point, or point-like object, containing the coordinates of the point around the circle.

Type
Phaser.Geom.Point | object

getPoints(quantity [, stepRate] [, output])

Returns an array of Point objects containing the coordinates of the points around the circumference of the Circle, based on the given quantity or stepRate values.

Parameters:
Name Type Argument Description
quantity number

The amount of points to return. If a falsey value the quantity will be derived from the stepRate instead.

stepRate number <optional>

Sets the quantity by getting the circumference of the circle and dividing it by the stepRate.

output array | Array.<Phaser.Geom.Point> <optional>

An array to insert the points in to. If not provided a new array will be created.

Since: 3.0.0
Inherited From:
Source: src/geom/circle/Circle.js (Line 129)
Returns:

An array of Point objects pertaining to the points around the circumference of the circle.

Type
array | Array.<Phaser.Geom.Point>

getRandomPoint( [point])

Returns a uniformly distributed random point from anywhere within the Circle.

Parameters:
Name Type Argument Description
point Phaser.Geom.Point | object <optional>

A Point or point-like object to set the random x and y values in.

Since: 3.0.0
Inherited From:
Source: src/geom/circle/Circle.js (Line 149)
Returns:

A Point object with the random values set in the x and y properties.

Type
Phaser.Geom.Point | object

isEmpty()

Checks to see if the Circle is empty: has a radius of zero.

Since: 3.0.0
Inherited From:
Source: src/geom/circle/Circle.js (Line 226)
Returns:

True if the Circle is empty, otherwise false.

Type
boolean

setColor(rgb)

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

Parameters:
Name Type Description
rgb number

The integer RGB color of the light.

Since: 3.0.0
Source: src/gameobjects/lights/Light.js (Line 119)
Returns:

This Light object.

Type
Phaser.GameObjects.Light

setEmpty()

Sets this Circle to be empty with a radius of zero. Does not change its position.

Since: 3.0.0
Inherited From:
Source: src/geom/circle/Circle.js (Line 188)
Returns:

This Circle object.

Type
Phaser.GameObjects.Light

setIntensity(intensity)

Set the intensity of the light.

Parameters:
Name Type Description
intensity number

The intensity of the light.

Since: 3.0.0
Source: src/gameobjects/lights/Light.js (Line 138)
Returns:

This Light object.

Type
Phaser.GameObjects.Light

setPosition( [x] [, y])

Sets the position of this Circle.

Parameters:
Name Type Argument Default Description
x number <optional>
0

The x position of the center of the circle.

y number <optional>
0

The y position of the center of the circle.

Since: 3.0.0
Inherited From:
Source: src/geom/circle/Circle.js (Line 205)
Returns:

This Circle object.

Type
Phaser.GameObjects.Light

setRadius(radius)

Set the radius of the light.

Parameters:
Name Type Description
radius number

The radius of the light.

Since: 3.0.0
Source: src/gameobjects/lights/Light.js (Line 155)
Returns:

This Light object.

Type
Phaser.GameObjects.Light

setScrollFactor(x [, y])

Sets the scroll factor of this Game Object.

The scroll factor controls the influence of the movement of a Camera upon this Game Object.

When a camera scrolls it will change the location at which this Game Object is rendered on-screen. It does not change the Game Objects actual position values.

A value of 1 means it will move exactly in sync with a camera. A value of 0 means it will not move at all, even if the camera moves. Other values control the degree to which the camera movement is mapped to this Game Object.

Please be aware that scroll factor values other than 1 are not taken in to consideration when calculating physics collisions. Bodies always collide based on their world position, but changing the scroll factor is a visual adjustment to where the textures are rendered, which can offset them from physics bodies if not accounted for in your code.

Parameters:
Name Type Argument Default Description
x number

The horizontal scroll factor of this Game Object.

y number <optional>
x

The vertical scroll factor of this Game Object. If not set it will use the x value.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/ScrollFactor.js (Line 64)
Returns:

This Game Object instance.

Type
Phaser.GameObjects.Light

setTo( [x] [, y] [, radius])

Sets the x, y and radius of this circle.

Parameters:
Name Type Argument Default Description
x number <optional>
0

The x position of the center of the circle.

y number <optional>
0

The y position of the center of the circle.

radius number <optional>
0

The radius of the circle.

Since: 3.0.0
Inherited From:
Source: src/geom/circle/Circle.js (Line 166)
Returns:

This Circle object.

Type
Phaser.GameObjects.Light

setVisible(value)

Sets the visibility of this Game Object.

An invisible Game Object will skip rendering, but will still process update logic.

Parameters:
Name Type Description
value boolean

The visible state of the Game Object.

Since: 3.0.0
Inherited From:
Source: src/gameobjects/components/Visible.js (Line 63)
Returns:

This Game Object instance.

Type
Phaser.GameObjects.Light

willRender(camera)

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 Description
camera Phaser.Cameras.Scene2D.Camera

The Camera to check against this Game Object.

Since: 3.50.0
Source: src/gameobjects/lights/Light.js (Line 103)
Returns:

True if the Game Object should be rendered, otherwise false.

Type
boolean