Class: Engine

core~Engine()

Manages the scenes and plugins. It is also responsible for all things concerning timing and the animation frame.

Constructor

new Engine()

Source:

Members

assets :module:core~Assets

A reference to the global Assets plugin.
Type:
Source:

background :string

The background color of the game for example '#f45a75' or 'tomato'. Can also be set to 'transparent'.
Type:
  • string
Source:

canvas :HTMLCanvasElement

A reference to the canvas element.
Type:
  • HTMLCanvasElement
Source:

context :CanvasRenderingContext2D

A reference to the 2d context of the canvas.
Type:
  • CanvasRenderingContext2D
Source:

delta :number

The time elapsed since the last frame.
Type:
  • number
Source:

foreground :string

The foreground color. Not used much. But can be handy if you are making a 2 color game.
Type:
  • string
Source:

plugins :Array.<object>

An array of instantiated global plugins.
Type:
  • Array.<object>
Source:

scenes :Array.<module:core~Scene>

An array of all the instantiated scenes.
Type:
Source:

time :number

The total time the game has been running in millieseconds. However if the browser window is not active (no frames are updated) then this value is not incremented.
Type:
  • number
Source:

timeouts :Array.<object>

An array keeping track of the setTimeout callbacks.
Type:
  • Array.<object>
Source:

Methods

clearTimeout(timeout)

Use this to cancel the timeouts created by the setTimeout method.
Parameters:
Name Type Description
timeout object The object returned by setTimeout method.
Source:

onFrame()

This method handles the browser's requestAnimationFrame and then calls all other update, render, draw and whatever functions in the system that need to run every frame.
Source:

setTimeout(callback, duration) → {object}

Works the same way as the native javascript setTimeout, but with the main difference that if the gameloop pauses (happens when the browser window becomes invisble) the callback is not executed, but the timer is paused and then resumed when the gameloop starts again.
Parameters:
Name Type Description
callback function The callback to be executed.
duration number How many millisceonds to wait before the callback gets executed.
Source:
Returns:
The timeout object. You can store this in a variable and then pass it to the clearTimeout function if you want to cancel the timeout.
Type
object

start()

Called by VerfGame instance to kick things off and start the first scene (the one you defined first in your game config).
Source:

switchScene(name)

Stops the current scene and starts the scene with the given name. Does nothing if the scene is already active. To restart the current scene use the scene's restart method.
Parameters:
Name Type Description
name string The name of the scene instance as defined by you in the game config.
Source: