Skip to content

DirectionalLight Class

SoJS coder edited this page Dec 12, 2023 · 3 revisions

DirectionalLight

The directional light class allows you to create directional lights (lights that face a certain direction in space)

Limited functionality (rotations do not work well)

Constructor

Parameters

new DirectionalLight(position, angle, spread, diffuse, strength, color)

  • position (Array): Vector representing the lights position in 2d space (x,y)
  • angle (Number): the angle that the light is facing (in radians)
  • spread (Number): The angle that the light spreads at (in radians)
  • diffuse (Number): How far the light diffuses
  • strength (Number): The strength of the light
  • color (Array): [r,b,b] 0-255

Works in the same way as the light class.

Methods

Inherits all methods from parent class light (pin, brighten, dim, move)

Additional methods:

pointTo(object, canvas)

Points the light to an object

  • object (GameObject): The game object to point the light to
  • canvas (HTMLCanvasElement): The canvas that the light is rendered on
myDirectionalLight.pointTo(polygon);

pinAngleTo(object)

Pins the angle to an object

  • object (GameObject): The game object to point the light to
myDirectionalLight.pinAngleTo(polygon);
Clone this wiki locally