Game

platypus. Game

This class is used to create the platypus.game object and loads the Platypus game as described by the game configuration files.

Configuration definition typically takes something like the following structures, but is highly dependent on the particular components used in a given game:

{
    "atlases": {}, // Keyed list of Spine atlases.
    "captions": {}, // Keyed list of captions for closed captioning.
    "entities": {}, // Keyed list of entity definitions.
    "levels": {}, // Keyed list of Tiled levels.
    "mouthCues": {}, // Keyed list of Rhubarb mouth cues for lip synch.
    "scenes": {}, // Keyed list of scene definitions.
    "skeletons": {}, // Keyed list of Spine skeletons.
    "spriteSheets": {} // Keyed list of sprite sheet definitions.
}

Options may include any of these:

{
    audio: '', // Relative path to audio assets (like "assets/audio/").
    canvasId: '', // HTML element ID for the canvas to draw to. If specified but unfound, will create a canvas with this ID.
    display: {}, // Display options are passed directly to PixiJS for setting up the renderer.
    features: { // Features supported for the Springroll application. Defaults are listed below.
        sfx: true,
        vo: true,
        music: true,
        sound: true,
        captions: true
    },
    images: '', // Relative path to graphical assets (like "assets/images/").
    name: '', // Name of game. Used for local storage keys and displayed in the console on run.
    storageKeys: [] // Array of keys to create in local storage on first run so game code may assume they exist.
    version: '' // Version of the game. This is displayed in the console on run.
}

Constructor

new Game(definition, options, onFinishedLoadingopt) → {platypus.Game}

Source:
Parameters:
Name Type Attributes Description
definition Object

Collection of configuration settings, typically from config.json.

options Object

Options describing the display options, Springroll features, etc.

onFinishedLoading function <optional>

An optional function to run once the game has begun.

Returns:
Type:
platypus.Game

Returns the instantiated game.

Extends

Members

destroyed :Boolean

This read-only property shows whether this Messenger is destroyed.

Properties:
Name Type Description
destroyed
Overrides:
Default Value:
  • false
Source:
Type:
  • Boolean

Methods

destroy()

This method destroys the game.

Overrides:
Source:

getEntitiesByType(type) → {Array}

This method will return all game entities that match the provided type.

Source:
Parameters:
Name Type Description
type String

The entity type to find.

Returns:
Type:
Array

entities Returns the entities that match the specified entity type.

getEntityById(id) → {Entity}

This method will return the first entity it finds with a matching id.

Source:
Parameters:
Name Type Description
id string

The entity id to find.

Returns:
Type:
Entity

Returns the entity that matches the specified entity id.

getMessageIds() → {Array}

This method returns all the messages that this entity is concerned about.

Overrides:
Source:
Returns:
Type:
Array

An array of strings listing all the messages for which this Messenger has handlers.

load(layerId, data, isScene, progressIdOrFunction)

Loads one or more layers.

If one layer is specified, it will complete loading if no other layers are already loading. If other layers are presently loading, it will complete as soon as other layers are complete.

If an array of layers is specified, all layers must finish loading before any receive a completion event.

Source:
Parameters:
Name Type Description
layerId Array | String

The layer(s) to load.

data Object

A list of key/value pairs describing options or settings for the loading scene.

isScene Boolean

Whether the layers from a previous scene should be replaced by these layers.

progressIdOrFunction String | function

Whether to report progress. A string sets the id of progress events whereas a function is called directly with progress.

Fires:

loadScene(layersOrId, data, progressIdOrFunction)

Loads a scene.

Source:
Parameters:
Name Type Default Description
layersOrId Array | Object | String

The list of layers, an object with a layers Array property, or scene id to load.

data Object

A list of key/value pairs describing options or settings for the loading scene.

progressIdOrFunction String | function scene

Whether to report progress. A string sets the id of progress events whereas a function is called directly with progress.

off(name, callback)

Remove the event listener

Overrides:
Source:
Parameters:
Name Type Description
name String

The type of event; if no name is specifed remove all listeners.

callback function

The listener function.

on(name, callback)

Add an event listener. The parameters for the listener functions depend on the event.

Overrides:
Source:
Parameters:
Name Type Description
name String

The type of event.

callback function

The callback function when event is triggered.

tick(ticker, tickMessage, deltaTime)

This method causes the game to tick once.

Source:
Parameters:
Name Type Description
ticker PIXI.Ticker

The ticker being used to set the game tick.

tickMessage Object

Event tracking tick data.

deltaTime number

The time elapsed since the last tick.

Fires:

toString()

Returns a string describing the Messenger as "[Messenger object]".

Overrides:
Source:
Returns:

String

trigger(event, value, debug) → {number}

This method is used by both internal components and external entities to trigger messages. When triggered, Messenger checks through bound handlers to run as appropriate. This handles multiple event structures: "", [], and {}

Overrides:
Source:
Parameters:
Name Type Description
event String | Array | Object

This is the message(s) to process. This can be a string, an object containing an "event" property (and optionally a "message" property, overriding the value below), or an array of the same.

value *

This is a message object or other value to pass along to event handler.

debug boolean

This flags whether to output message contents and subscriber information to the console during game development. A "value" object parameter (above) will also set this flag if value.debug is set to true.

Returns:
Type:
number

The number of handlers for the triggered message.

triggerEvent(event, valueopt) → {number}

This method is used by both internal components and external entities to trigger messages on this entity. When triggered, entity checks through bound handlers to run as appropriate. This method is identical to Spring Roll's EventDispatcher.trigger, but uses alternative Array methods to alleviate excessive GC.

Overrides:
Source:
Parameters:
Name Type Attributes Description
event String

This is the message to process.

value * <optional>

This is a message object or other value to pass along to event handler.

Name Type Attributes Description
debug boolean <optional>

This flags whether to output message contents and subscriber information to the console during game development.

Returns:
Type:
number

The number of handlers for the triggered message.

triggerOnChildren(eventId, event)

This method is used by external objects to trigger messages on the layers as well as internal entities broadcasting messages across the scope of the scene.

Source:
Parameters:
Name Type Description
eventId String

This is the message to process.

event *

This is a message object or other value to pass along to component functions.

unload(layer)

Unloads a layer.

Source:
Parameters:
Name Type Description
layer String | Object

The layer to unload.

Events

tick

This event is triggered on the game as well as each layer currently loaded.

Source:
Parameters:
Name Type Description
tickMessage Object

Event tracking tick data. This object is re-used for subsequent ticks.

Name Type Description
delta Number

Time in MS passed since last tick.

elapsed Number

Time in MS passed since game load.