Class Light

Classdesc

Light class, used for creating lights in the scene

Example

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

Example

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

Hierarchy (view full)

Constructors

  • Parameters

    • position: Vec2

      The position of the light in wolrd space [x,y]

    • diffuse: number

      How far the light diffuses, in pixels

    • strength: number = 0.8

      The strength of the light. Default is 0.8

    • color: number[] = ...

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

    Returns Light

Properties

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.

point: Vec2

Coordinates of the light

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

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

    Parameters

    • canvas: HTMLCanvasElement

      The canvas to draw the light on (Optional).

    Returns void

Generated using TypeDoc