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

Methods

destroy()

This method destroys the game.

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.

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.

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:

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.