Class Scene

Classdesc

Scene class, used for building scenes

Example

const scene = new Scene({
lighting: true,
physics: true,
physicsOptions: {
gravity: {
x: 0,
y: 0
}
}
});

Example

const scene = new Scene({
lighting: true,
physics: true,
physicsOptions: {
gravity: {
x: 0,
y: 0
}
},
lightOptions: {
fog: 1.3,
ambient: 0.2
}
});

Example

const scene = new Scene({
layers: [background, middle, foreground]
});

Constructors

Properties

FPS_BUFFER_SIZE: number

Size of the fps buffer

GPUSettings: Object

GPU.js settings

ambient: number

Ambient of the scene

backgroundColor: string

Background color of the scene

bounds: Vec2

Bounds of the scene

boundsActive: boolean

Whether or not the bounds are active

cameraAngle: Vec2

Position of the camera

cameraBind: null | GameObject

Object to bind the camera to

canvas: HTMLCanvasElement

Canvas of the scene

clearScene: boolean

Whether or not to clear the scene

collisionMonitors: CollisionMonitor[]

Collision monitors in the scene

ctx: CanvasRenderingContext2D

Canvas rendering context of the scene

diffuseKernel: any

GPU.js kernel for diffuse lighting

dlights: DirectionalLight[]

Directional lights in the scene

drawMode: "full" | "plain"

Draw mode of the scene. "full" is defualt and used when objects need to be updated as well. "plain" just draws objects (eg: when the scene is handled on the server)

fog: number

Fog of the scene

formattedDLights: number[]

Formatted directional lights for the diffuse kernel

formattedLights: number[]

Formatted lights for the diffuse kernel

fpsBuffer: number[]

Buffer that holds the last FPS_BUFFER_SIZE frames rendering times (in ms)

fpsMonitoringEnabled: boolean

Whether or not to monitor the fps

gpu: any

GPU.js instance

height: number

Height of the scene

id: string

Unique ID of the scene

isActiveScene: boolean

Whether or not the scene is the active scene

isClient: boolean

Whether or not the scene is running on the client

lastFrameStamp: number

Last frame stamp

layers: Layer[]

Layers of the scene

lighting: boolean

Whether or not lighting is enabled

lights: Light[]

Lights in the scene

lightsPreFormatted: boolean

Whether or not the lights are pre-formatted

objects: GameObject[]

Objects in the scene

readyToDraw: boolean

Whether or not the scene is ready to draw

update: Function

Update function of the scene (called every frame)

width: number

Width of the scene

Methods

  • Enables the boundaries of the scene

    Returns void

  • Used to add lights to the scene

    Parameters

    Returns void

  • Adds the specified GameObject to the scene

    Parameters

    • object: GameObject

      GameObject to add to the scene

    • Optional layerID: string

    Returns void

  • Binds the scene's camera to a GameObject

    Parameters

    • object: GameObject

      GameObject to bind the scene's camera to

    Returns void

  • Moves the camera to a GameObject

    Parameters

    • object: GameObject

      GameObject to move the camera to

    Returns void

  • Checks to see if the scene is configured to draw, if not, it configures it (eg: initializes lighting kernel, etc.)

    Returns void

  • Clears the canvas that the scene is being drawn on

    Returns void

  • Configures the lighting kernel (if lighting is enabled and the scene is on the client side)

    Returns void

  • Renders lights onto the scene. Automatically calculates if lights are in the camera view and removes them from the render if they are not.

    Parameters

    • ambient: number = 0.2

      The ambient lighting in the scene

    • fog: number = 1.3

      The fog constant in the scene

    Returns void

  • Disables the boundaries of the scene

    Returns void

  • Disables FPS monitoring

    Returns void

  • Draws all of the objects, lights, and directional lights in the scene. Also updates each physics object and checks for collisions. It also recalculates the FPS if enabled.

    Returns void

  • Reloads scene objects from the passed list, used for multiplayer when objects are handled on the server

    Parameters

    Returns void

  • Enables collisions between the specified objects Adds a CollisionMonitor to the scene

    Parameters

    • o1: GameObject

      First object to check for collisions

    • o2: GameObject

      Second object to check for collisions

    • fo: Function

      Function that runs when the objects collide (called once)

    • ff: Function

      Function that runs when the objects separate (called once)

    • Optional options: CollisionMonitorOptions

      Options for the collision monitor

    Returns void

  • Enables FPS monitoring

    Returns void

  • Formats the directional lights into a format that the diffuseKernel can understand Updates the formattedDLights property

    Parameters

    Returns number[]

  • Formats the lights into a format that the diffuseKernel can understand Updates the formattedLights array property

    Parameters

    • lights: Light[]

      List of lights in the scene

    • Optional cameraAngle: Vec2

    Returns number[]

  • Moves the scene's camera

    Parameters

    • vector: Vec2

      Vector to move the scene's camera by

    Returns void

  • Draws the scene without updating any of the objects

    Returns void

  • Initializes the scene, specifically the light rendering kernel

    Returns void

  • Removes a GameObject from the scene

    Parameters

    • object: GameObject

      GameObject to remove from the scene

    Returns void

  • Sets the boundaries of the scene (eg: where object can move)

    Parameters

    • rightBound: number

      How far right (in pixel) can objects in the scene move. If object are initialized outside the bounds, they will not be able to move, unless physics is enabled, in which case they will not be able to enter the scene.

    • bottomBound: number

      How far down (in pixel) can objects in the scene move. If object are initialized outside the bounds, they will not be able to move, unless physics is enabled, in which case they will not be able to enter the scene.

    • activate: boolean = true

      Boolean, if true, bounds will be active by defualt, if false, bounds will be inactive by default

    Returns void

  • Configures the scene to draw on the provided canvas

    Parameters

    • canvas: HTMLCanvasElement

      Canvas that the scene will draw on

    • ctx: CanvasRenderingContext2D

      The canvas rendering context of the scene

    • width: number

      The width of the scene

    • height: number

      The height of the scene

    • drawMode: string = "full"

    Returns void

  • Used to quickly set up an object as the player. Binds the camera to the object and sets up WASD movement (the object will move movementSpeed pixels every 10ms) (Only for sigle-player games)

    Parameters

    • object: GameObject

      GameObject to configure as player

    • movementSpeed: number = 2

      How quickly the player should move

    Returns void

  • Unbinds the scene's camera from a GameObject

    Returns void

  • Updates all of the objects, lights, physics, and collision monitors in the scene

    Returns void

  • Updates all lights in the scene

    Returns void

Generated using TypeDoc