-
Notifications
You must be signed in to change notification settings - Fork 1
Light Class
SoJS coder edited this page Dec 12, 2023
·
4 revisions
The Light class represents a light source within a 2D scene. It allows for the manipulation of the light's position, brightness, color, and interaction with other objects. This documentation outlines the properties and methods of the Light class. For a directional light, use the DirectionalLight class.
-
position
(Array, required): An array representing the initial position of the light source. -
diffuse
(Number, required): How much the light is diffused across a scene. -
strength
(Number, optional): The strength of the light source. Default is 0.8. -
color
(Array, optional): An array representing the RGB color of the light. Default is [255, 255, 255].
const lightPosition = [100, 100];
const diffuse = 0.5;
const lightStrength = 0.8;
const lightColor = [255, 255, 255];
const myLight = new Light(lightPosition, diffuse, lightStrength, lightColor);
To add the light to the scene, use scene.addLight(myLight)
. (Ensure that scene.lighting
is set to true)
-
point
(Array): An array representing the current position of the light source. -
diffuse
(Boolean): How the light diffuses across a scene. -
strength
(Number): The strength of the light source. -
color
(Array): An array representing the RGB color of the light. -
pinnedTo
(Object): The object to which the light source is pinned, if any
Pins the light source to a specified object.
-
object
(Object): The object to which the light source is pinned.
const myObject = /* some GameObject (Polygon/Sprite) */;
myLight.pin(myObject);
Increases the brightness of the light source by a specified factor.
-
factor
(Number): The factor by which to increase the brightness.
const brightnessFactor = 1.2;
myLight.brighten(brightnessFactor);
Decreases the brightness of the light source by a specified factor.
-
factor
(Number): The factor by which to decrease the brightness.
const dimmingFactor = 0.8;
myLight.dim(dimmingFactor);
Moves the light source by a specified vector.
-
vector
(Array): An array representing the movement vector. (x,y)
const movementVector = [10, 0];
myLight.move(movementVector);
Moves the light source to the center of a specified object.
-
object
(Object): The GameObject to which the light source should move.
const myObject = myPolygon;
myLight.moveToObject(myObject);