Class MultiPlayerSceneManager

Classdesc

MultiPlayerSceneManager class, used for managing scenes, players, and transitions between scenes in a multiplayer game

Example

const sceneManager = new MultiPlayerSceneManager({
initialScene: scene,
canvas: createCanvas(), // create a synthetic canvas... nothing will be rendered on it, it is just for SceneManager to use under the hood
width: 500,
height: 500,
showPlayerLabels: true
});

Hierarchy (view full)

Constructors

Properties

activeScene: string

ID of the active scene

animateTo: Scene

Scene to animate to

animationNames: string[]

Names of the animations that can be used

animationRunTime: number

How long the animation should run for

animationRunning: boolean

Whether or not the animation is running

animationStartTime: number

Time when the animation started

canvas: HTMLCanvasElement

Canvas element to draw the scenes on

ctx: CanvasRenderingContext2D

Canvas rendering context of the canvas

fromScenePrevHadLights: boolean

Whether or not the scene that the animation is coming from had lighting enabled

height: number

Height of the canvas (Will resize the canvas to this height). By default is the width of the canvas element

players: Player[]

Array of players in the scene manager

sceneAnimation: string

Animation to use when transitioning between scenes

scenes: {
    [key: string]: Scene;
}

Scenes in the scene manager

Type declaration

showPlayerLabels: boolean

Whether or not to show player labels

start: boolean

Whether or not to start the scene manager when it is initialized (true by default)

toScenePrevHadLights: boolean

Whether or not the scene that the animation is going to had lighting enabled

width: number

Width of the canvas (Will resize the canvas to this width). By default is the width of the canvas element

Methods

  • Adds a player into the scene manager

    Parameters

    • player: Player

      Player to add to the scene manager

    Returns void

  • Smoothly animates between scenes (unless lighting is enabled, in which case lighting is temporarily disabled as the animation is running)

    Parameters

    • transition: string

      Name of the transition to use

    • scene: Scene

      Scene to transition to

    • duration: number = 1000

      Time (in ms) to run the transition for

    Returns void

  • Retrieves a given player from the scene manager. Has O(n) time complexity, so not recommended to use often

    Parameters

    • id: string

      ID of the player to get

    Returns Player

    The player with the given ID

  • Retrieves a given player from the scene manager. Has O(n) time complexity, so not recommended to use often

    Parameters

    • label: string

      Label of the player to get

    Returns Player

    The first player with the given label

  • Gets all players that match a given label

    Parameters

    • label: string

      Label of the players to get

    Returns Player[]

    Array of players with the given label (eg: if multiple players have the same label)

  • Removes a player from the scene manager

    Parameters

    • player: Player

      Player to remove from the scene manager

    Returns void

Generated using TypeDoc