Class Layer

Classdesc

Layer class, used for creating layers in the scene. Layers are independent of each other, and can have their own physics engines, objects, etc. Like multiple scenes within a single scene, drawn on top of each other.

Example

 const background = new Layer({
parallax: [0.75, .75]
});
background.addObject(...);
const foreground = new Layer();
foreground.addObject(...);
foreground.addObject(...);

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

Constructors

Properties

Bodies: any

Matter.js Bodies

Composite: any

Matter.js Composite

Engine: any

Matter.js Engine

bounds: number[]

Bounds of the layer

boundsActive: boolean

Whether or not the bounds are active

engine: any

Matter.js engine instance

id: String

Unique ID of the layer

lastPhysicsUpdate: number

Last time the physics were updated in the layer

objects: GameObject[]

Objects in the layer

parallax: Vec2

How the layer processes camrea position. [1, 1] by default. [0, 0] would mean the layer is fixed to the camera, [1, 1] would mean the layer moves with the camera, [2, 2] would mean the layer moves at twice the speed of the camera, etc.

physics: boolean

Whether or not the layer has physics enabled

Methods

  • Activates the bounds of the layer

    Returns void

  • Adds an object to the layer

    Parameters

    • object: GameObject

      The object to add to the layer

    • scene: Scene

      A reference to the parent scene

    Returns void

  • Disables the bounds of the layer

    Returns void

  • Draws the layer onto the provided drawing context. This is handled automatically with scene and scene managers

    Parameters

    Returns void

  • Removes an object from the layer

    Parameters

    • object: GameObject

      The object to remove from the layer

    Returns void

  • Sets the boundaries of a scene

    Parameters

    • rightBound: number

      How far to the right objects can go

    • bottomBound: number

      How far down objects can go

    • canvas: HTMLCanvasElement

      The canvas that the layer is drawn on

    • activate: boolean = true

      Whether or not to activate the bounds. True by default. If the scene has physics enabled, the bounds will be activated no matter what.

    Returns void

Generated using TypeDoc