Play Sound

Play a sound effect

Description

'play sound <sound_id> [with [loop] [fade <time>] [volume <percentage>] [<effects>]]'
'play sound'  // Resume all paused sounds

The play sound action lets you play sound effects in your game. You can play as many sound effects as you want simultaneously.

To stop the sound, check out the Stop Sound documentation.

Action ID: Play

Reversible: Yes

Requires User Interaction: No

Parameters

Name
Type
Description

sound_id

string

The name of the sound you want to play. These assets must be declared beforehand.

loop

flag

Optional. Makes the sound loop indefinitely.

fade

number

Optional. Fade in time in seconds.

volume

number

Optional. Volume percentage (0-100).

effects

various

Optional. Audio effects to apply (see Audio Effects).

Assets Declarations

To play a sound, you must first add the file to your assets/sounds/ directory and then declare it. To do so, Monogatari has a function that will let you declare all kinds of assets for your game.

Supported Formats

Each browser has its own format compatibility. MP3 however is the format supported by every browser.

If you wish to use other formats, you can check a compatibility table to discover what browsers will be able to play it.

Examples

Play Sound

The following will play the sound, and once the sound ends, it will simply stop.

Loop Sound

The following will play the sound, and once the sound ends, it will start over on an infinite loop until it is stopped using the Stop Sound Action.

Fade In Effect

The following will play the sound with a fade in effect.

Custom Volume

The following will set the volume of this sound to 73%.

Please note that the user's preferences regarding volumes are always respected, which means this percentage is taken from the current player preferences. If the player has set the volume to 50%, the actual volume value for the sound will be:

50%×73%=36.5%50\% \times 73\% = 36.5\%

Resume Paused Sounds

If sounds have been paused using the Pause action, you can resume them:

All Together

You can combine all properties. The order doesn't matter.

Audio Effects

Sound effects support the same audio effects system available for music, including filter, delay, compressor, tremolo, distortion, reverb, and many more. See the Play Music documentation for a complete list of available effects and their usage.

Example with Effects

This plays an explosion sound with a low-pass filter and reverb for a more distant, muffled effect.

  • Stop Sound - Stop playing sounds

  • Pause - Pause playing media

  • Play Music - Play background music (includes full audio effects documentation)

Last updated

Was this helpful?