Class PlayerClient

Classdesc

PlayerClient class, used for constructing, running, and managing a multiplayer client

Example

const playerClient = new ANVIL.PlayerClient({
canvas: document.getElementById('canvas'),
modifyLocalObject: function (obj) {
obj.backgroundColor = "blue";
this.scene.bindCamera(obj)
},
sceneOptions: {
fpsMonitoringEnabled: true
}
});

Indexable

[key: string]: any

Constructors

Properties

canvas: HTMLCanvasElement

Canvas to draw the scene on

ctx: CanvasRenderingContext2D

CanvasRenderingContext2D of the canvas

Stack data to emitwhen the client is ready

height: number

Height of the scene

Stack of inputs to activate when the client is ready

io: any

Socket.io instance (used to generate socket)

localPlayer: null | GameObject

Local player's GameObject

modifyLocalObject: ((gameObject) => void)

Function to modify the local player's GameObject

Type declaration

    • (gameObject): void
    • Function to modify the local player's GameObject

      Parameters

      Returns void

objects: GameObject[]

Array of GameObjects in the scene

ready: boolean

Whether or not the client is ready

scene: Scene

A Scene reference used to render the objects and lights sent by the server

socket: any

Socket.io socket of the client

width: number

Width of the scene

Methods

  • Draws the scene on the canvas

    Returns void

  • Emits an event to the server

    Parameters

    • event: string

      Event to emit. "key_down", "key_up", "player_data", and "player_initialized" are reserved events.

    • data: any

      Data to send to the server

    Returns void

  • Emits data to the server

    Parameters

    • data: any

      Data to send to the server

    Returns void

  • Initializes the client after socket.io is loaded, empties the emitStack and inputStack, and sets the client to ready

    Parameters

    • io: any

      Socket.io instance

    Returns void

  • Listens for an event, fires the given callback when the event is fired.

    Parameters

    • event: string

      Event to listen to

    • callback: Function

      Callback to run when the event is fired

    Returns void

  • Empties the emitStack and inputStack, and sets the client to ready, starts the render loop

    Returns void

  • Updates the scene with data from the server

    Parameters

    • data: any

      Data to update the client with (Updates lights, objects, fog, ambient lighting, and directional lights)

    Returns void

  • Updates the client's local player

    Parameters

    • data: any

      Sets the local player

    Returns void

Generated using TypeDoc