Skip to content

Light Class

SoJS coder edited this page Dec 11, 2023 · 4 revisions

Light Class

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.

Constructor

Parameters

  • 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].

Example Usage

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)

Properties

  • 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
Clone this wiki locally