Module: engine/core

Engine core that manages game loop and resize functionality.

Source:

Requires

Members


<static> containerView :HTMLCanvasElement

Div that contains game canvas.

Type:
  • HTMLCanvasElement
Source:

<static> game :Game

Current activated game.
Note: this may be undefined during switching.
Will be deprecated in future versions.

Type:
Source:

<static> games :object

Map of registered games.

Type:
  • object
Source:

<static> pauses :object

Map that contains pause state of all kinds of reasons.
See core.pause for more information.

Type:
  • object
Source:

<static> resizeFunc :function

Current resize function.

Type:
  • function
Source:

<static> resolution :Number

Canvas resolution properly choosed based on configs.

Type:
Source:

<static> rotatePromptElm :HTMLElement

Rotate prompt element for mobile devices.

Type:
  • HTMLElement
Source:

<static> rotatePromptVisible :boolean

Whether the rotate prompt is visible.

Type:
  • boolean
Source:

<static> sayHello :Boolean

Set to false to disable version info console output.

Type:
  • Boolean
Source:

<static> size :Vector

Size of game content.

Type:
Default Value:
  • (640, 400)
Source:

<static> speed :number

Global time speed, whose value is between 0 and 1.

Type:
  • number
Default Value:
  • 1
Source:

<static> version :string

Version text.

Type:
  • string
Source:

<static> view :HTMLCanvasElement

Main Canvas element.

Type:
  • HTMLCanvasElement
Source:

<static> viewSize :Vector

Size of view (devicePixelRatio independent).

Type:
Source:

Methods


<static> main(gameCtor, loaderCtor)

Main entry.

Parameters:
Name Type Description
gameCtor Game

First game class

loaderCtor Game

Asset loader class

Source:

<static> pause( [reason])

Pause the engine with a reason.

Parameters:
Name Type Argument Default Description
reason String <optional>
'untitled'

The reason to pause, you have to pass
the same reason when resume from this
pause.

Source:
Example
import core from 'engine/core';
// Pause when ad is playing
core.pause('ad');
// And resume after the ad finished
core.resume('ad');

<static> resume( [reason] [, force])

Unpause the engine.

Parameters:
Name Type Argument Default Description
reason String <optional>
'untitled'

Resume from pause tagged with this reason

force Boolean <optional>
false

Whether force to resume

Source:

<static> setGame(gameCtor [, newInstance] [, param])

Switch to a game.

Parameters:
Name Type Argument Default Description
gameCtor Game

Game class to be set

newInstance Boolean <optional>
false

Whether create new instance for this game.

param Object <optional>
{}

Parameters to pass to the game(to Game#awake)

Source: