API Docs for: 0.1.0
Show:

zerk.game.engine Class

Game Engine

The game engine main class

Methods

_getSystemClass

(
  • name
)
String protected

Returns the class name for given system name

Parameters:

  • name String

    System name. Not the class name.

Returns:

String: Class name of the system

_log

(
  • message
  • severity
)
protected

Local log method

Parameters:

  • message String

    Log message

  • severity Integer

    Log severity

_onLoadWorld

(
  • world
  • successHandler
  • errorHandler
)
protected

Fires when the world definition is laoded

Parameters:

  • world Object

    World definition

  • successHandler Function

    Event handler for success

  • errorHandler Function

    Event handler for error

_render

() protected

Game engine render tick

_startTimer

() protected

Starts the engine timer

_stopTimer

() protected

Stops the engine timer

_tick

() protected

Game engine simulation tick

_updateSystems

(
  • thread
)
protected

Updates all systems in given thread

Parameters:

  • thread String

    Thread name

addEntity

(
  • config
)

Creates a new entity instance with given configuration

Parameters:

addSystem

(
  • name
  • config
)
Boolean

Adds a system to the engine

Parameters:

  • name String

    Name of the system. Not the class name.

  • config Object

    Initial config for the system

Returns:

Boolean: True on success

clearEntities

()

Removes all entities from the world

clearSystems

()

Removes all system from the engine

fireEvent

(
  • event
)
Boolen

Fire event

Parameters:

  • event String

    Event name

Returns:

Boolen: Returns false when the bubble was canceled

getEntitiesByTags

(
  • tags
)
Array

Returns entites that contain all given tags

Parameters:

  • tags Array

    Array of tags

Returns:

Array: Array of entities

getEntityById

(
  • id
)
Null | config.entity

Returns entity instance by given id

Parameters:

  • id String

    Entity id

Returns:

Null | config.entity: Entity or null

getEntitySystemList

(
  • entity
)
Array

Returns a list of systems interested in given entity

Parameters:

Returns:

Array: Array of systems

getRegistry

() zerk.game.engine.registry

Returns the game engine registry

Returns:

zerk.game.engine.registry: Returns the registry instance

getSystem

(
  • name
)
zerk.game.engine.system

Returns a system instance

Parameters:

  • name String

    System name. Not the class name.

Returns:

zerk.game.engine.system: System instance

getTime

() Integer

Returns current world time

Returns:

Integer: World time

init

(
  • jsonLoader
  • config
)

Inherited from zerk.observable but overwritten in src/zerk/class/game/engine.js:186

Class constructor

Parameters:

  • jsonLoader zerk.jsonLoader

    A JSON Loader instance

  • config Object

    Game configuration

isRunning

() Boolean

Returns true if the game engine is running

Returns:

Boolean: True if the game engine is running

isSystemRegistered

(
  • name
)
Boolean

Returns true when given system is loaded in the engine

Parameters:

  • name String

    System name. Not the class name.

Returns:

Boolean: True when the system is loaded

loadEntities

(
  • entities
  • successHandler
  • errorHandler
)
async

Loads given entities

Parameters:

  • entities Array

    An array of entity resource ids

  • successHandler Function

    Event handler for success

  • errorHandler Function

    Event handler for error

loadWorld

(
  • worldClass
  • successHandler
  • errorHandler
)
async

Loads a world

Parameters:

  • worldClass String

    Resource id of the world to be loaded

  • successHandler Function

    Event handler for success

  • errorHandler Function

    Event handler for error

on

(
  • event
  • callback
  • scope
)

Register event handler

Parameters:

  • event String

    Event name

  • callback Function

    Callback function. Return false to cancel event bubble.

  • scope Object

    Scope to be used in callback function

pause

()

Pause game engine

removeEntity

(
  • Entity
)
Boolean

Removes given entity instance from the world

Parameters:

Returns:

Boolean: Returns true on success

removeSystem

(
  • name
)
Boolean

Removes a system from the engine

Parameters:

  • name String

    Name of the system. Not the class name.

Returns:

Boolean: True on success

reset

()

Reset the engine

saveWorld

() String

Save world state

Returns:

String: World state as JSON string

start

()

Start game engine

startSystems

()

Starts all systems

stop

()

Stop game engine

stopSystems

()

Stops all systems

un

(
  • event
  • callback
)
Boolen

Unregister event handler

Parameters:

  • event String

    Event name

  • callback Function

    Callback function

Returns:

Boolen: Returns true on success

Properties

_componentLoader

zerk.game.engine.componentLoader protected

Component loader instance

_config

Object protected

Engine configuration

_entities

Array protected

Entities register

_entityIdMap

Object protected

Entity id map

_entityLoader

zerk.game.engine.entityLoader protected

Entity loader instance

_eventListeners

Array protected

List of event handlers

_jsonLoader

zerk.jsonLoader protected

JSON loader instance

_lastEntityId

Integer protected

Last used entity id

Used to generate the next entity id.

_registry

zerk.game.engine.registry protected

Game engine registry

_running

Boolean protected

Indicates that the engine is running

_system

Object protected

System register

_systemMap

Object protected

Map of systems by names

_threadMap

Object protected

Entities grouped by threads for fast access

_time

Integer protected

Total world runtime

_timer

DOMTimer protected

World timer

_unloadingWorld

Boolean deprecated protected

Indicates that the world is unloading

_worldInterval

Float protected

World timer interval

_worldLoader

zerk.game.engine.worldLoader protected

World loader instance