GameWorld

GameWorld

This class represents an instance of the game world, where all data pertaining to the current state of the world is saved.

Constructor

new GameWorld()

Constructor of the World instance

Source:

Methods

addObject(object)

Add an object to the game world

Parameters:
Name Type Description
object Object

object to add

Source:

forEachObject(callback)

World object iterator. Invoke callback(objId, obj) for each object

Parameters:
Name Type Description
callback function

function receives id and object. If callback returns false, the iteration will cease

Source:

getNewId() → {Number}

Gets a new, fresh and unused id that can be used for a new object

Source:
Returns:

the new id

Type
Number

queryObject(query) → {Object}

Returns The first game object encountered which matches a criteria. Syntactic sugar for queryObject with returnSingle: true

Parameters:
Name Type Description
query

See queryObjects

Source:
Returns:
Type
Object

queryObjects(query) → {Array|Object}

Returns all the game world objects which match a criteria

Parameters:
Name Type Description
query Object

The query object

Properties
Name Type Attributes Description
id Object <optional>

object id

playerId Object <optional>

player id

instanceType Class <optional>

matches whether object instanceof instanceType

components Array <optional>

An array of component names

returnSingle Boolean <optional>

Return the first object matched

Source:
Returns:

All game objects which match all the query parameters, or the first match if returnSingle was specified

Type
Array | Object

removeObject(id)

Remove an object from the game world

Parameters:
Name Type Description
id number

id of the object to remove

Source: