Class DirectionalLightBeta

Classdesc

DirectionalLight class, used for creating directional lights in the scene

Devnote

Directional lights are not fully implemented yet. They are not recommended for use.

Example

// light at position [0, 0], diffuse 150, strength 0.8, color [255, 255, 255] (white)
const light = new DirectionalLight([0, 0], 150, 0.8, [255, 255, 255]);

Hierarchy (view full)

Constructors

  • Parameters

    • position: Vec2

      Position of the light in the world. [x,y]

    • angle: number

      Angle of the light, in radians

    • spread: number

      The spread of the light, in radians

    • diffuse: number

      How far the light diffuses, in pixels

    • strength: number

      The strength of the light.

    • color: number[] = ...

      The color of the light, [r,g,b]. By defualt is [255, 255, 255] (white)

    Returns DirectionalLight

Properties

angle: number

Angle of the light (in radians)

color: number[]

Color of the light. Format is [r,g,b]. White by default

diffuse: number

How much the light diffuses (measured in pixels)

pinnedTo: null | GameObject

Object to pin the light's position to. Null by default.

pinnedToAngle: null | GameObject

Object to pin the light's angle to. Null by default.

point: Vec2

Coordinates of the light

spread: number

Spread of the light (in radians)

strength: number

Strength of the light. No matter how strong it is, it will never go past the bounds defined by diffuse

type: string

Type of the light, either "light" or "directional"

Methods

  • Brightens the light by the specified factor

    Parameters

    • factor: number

      The factor to brighten the light by

    Returns void

  • Dims the light by the specified factor

    Parameters

    • factor: number

      The factor to dim the light by

    Returns void

  • Moves the light by the specified vector

    Parameters

    • vector: Vec2

      The vector to move the light by

    Returns void

    Example

    const light = new Light([0, 0], 0.5);
    light.move([10, 10]); // moves the light ten pixels to the right and ten pixels down
  • Moves the light to the center of the specified GameObject (Good for things like lanterns, etc.)

    Parameters

    • object: GameObject

      GameObject to move the light's position to

    Returns void

  • Pins the light's position to a certain GameObject

    Parameters

    • object: GameObject

      The GameObject to pin the light to

    Returns void

  • Pins the angle of the light toward a given GameObject

    Parameters

    • object: GameObject

      GameObject to pin the light's angle to (points the light to the center of the object)

    Returns void

  • Point the light to a certain object

    Parameters

    • object: GameObject

      Object to point the light to

    • canvas: HTMLCanvasElement

      Canvas that the light is being rendered on (used for calculating the angle)

    Returns void

  • Updates the light's position and angle if pinned to an object, otherwise does nothing

    Parameters

    • canvas: HTMLCanvasElement

      Required to calculate the angle of the light (if the angle is pinned)

    Returns void

Generated using TypeDoc