device parameter of the Sprite methods can be used to interact with the platform, like reading inputs and playing sound effects.
Math.random. Using these ensures the game works across all platforms and tests (plus it keeps your Sprite methods pure).
An object of the device's input state. The value depends on the platform your game is running on. See Platforms for the values available.
Platforms share similar input object shapes. For example, both the web and iOS platforms have a
pointer field (relative to the Sprite's position):
The pointer is relative to the Sprite's position and rotation. If your Sprite has an
x position of
100, and you click at an
x position of
50, the value of
inputs.pointer.x in the Sprite will be translated to
-50. To do this translation in Replay Test you can pass in a
An object of the device's size. See Game Size for info on this.
A platform independent way of logging messages. Replaces
Returns a random number between 0 - 1. Replaces
Run, pause and cancel timers.
Run a callback after a time in milliseconds, returns an
id string. Replaces
Pause a timer using its ID.
Resume a paused timer using its ID.
Cancel a timer using its ID. It will not be possible to resume the timer, but the callback is cleaned up.
Get the current time and date as a Date object. Replaces
Play audio files in your game.
The returned object has the following methods:
Play the sound file.
loop arguments are optional.
Pause the sound file.
Get the current play position of the sound in seconds.
Make platform-independent networks calls. Returns and sends data as a JSON object.
Platform-independent way of storing save data to the local device.
Returns the current store: an object of keys and values of type string.
Add or remove fields in the store. New fields are merged into the existing store:
undefined will remove a field from storage:
Show an alert using the platform's dialog.
An alert dialog with an OK button. Game loop will be paused on some platforms.
An alert dialog with an OK and cancel button. Game loop will be paused on some platforms.
Interact with the player's clipboard.
Asynchronously copy text to the clipboard. Callback has an error argument if unsuccessful (e.g. did not get permission).
Boolean to indicate if the device is a touch screen device.