getInputs parameters of the Sprite methods can be used to interact with the platform, like getting mouse coordinates and playing sound effects.
Math.random. Using these ensures the game works across all platforms and tests (plus it keeps your Sprite methods pure).
A function which returns 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 mobile 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.
Note that the file must be loaded using
preloadFiles before you can play it.
The returned object has the following methods:
Play the audio file. If the file is already playing, another sound will be played at the same time (unless
overwrite is set to
The first argument is optional and can be a number (start time in seconds) or an object with the following fields:
fromPosition: (Optional) Where to start the audio file from in seconds, same as providing the first argument as a number.
overwrite: (Optional) If this audio file is already playing, remove it first. Default
loop: (Optional) Keep playing the audio when it finishes. Default
playbackRate: (Optional) The speed to play at, less than
1slows audio down and more than
1speeds it up. Default
If no argument is provided or
fromPosition is not defined in the argument object:
- The audio will play from the beginning if:
- It's the first time being played, or
- The audio is already playing and
overwriteis not set to
- Otherwise, the audio will continue from where it was paused.
Pause the sound.
Get the current play position of the sound in seconds.
Get current status of the sound (as a string):
Get the total duration of the sound in seconds.
Set the volume of the sound. Resets when sound finishes playing. Argument can be a number (1 is maximum (default), 0 is muted) or an object with the following fields:
fadeTo: Volume to fade to. Must be between 0 - 1.
fadeTime: Total fade time in seconds, starts immediately after calling.
Get the volume of the sound. 1 is maximum, 0 is muted.
Make platform-independent networks calls. Returns and sends data as a JSON object.
Platform-independent way of storing save data to the local device.
Retrieve a saved value by its
string key. Returns a
Set or remove a value in storage.
null 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.
Change the resolution the game is rendered at (# pixels drawn in shaders).
Should be a scalar -
1 is full size,
0.5 is half device size.
Returns the resolution as a number.
Set the resolution. This value is automatically saved to local storage.