Skip to content
Greg Rogers edited this page Jan 5, 2020 · 2 revisions

Plugins are objects that can be installed into the engine directly in order to receive and propagate updates every tick as well as handle engine resets for cleanup. Existing plugins include Physics, RendererStats, Light, and Controls. You can define and install your own plugin if it fits your needs.

As an example, let's say you want to create a CountdownScoreboard within your game. You'd define it as such:

class CountdownScoreboard extends Plugin {
  constructor() {
    super();
    // Start at 5 minutes.
    this.remainingTime = 1000 * 60 * 5
    this.lastTime = Date.now();
  }

  /** @override */
  update() {
    const currTime = Date.now();
    this.remainingTime -= currTime - this.lastTime;
    this.lastTime = currTime;
  }  

  /** @override */
  reset() {
    this.lastTime = Date.now();
    this.remainingTime = 1000 * 60 * 5;
  }
}

When you need it, simply call:

const scoreboard = new CountdownScoreboard();
Clone this wiki locally