Hello guest! Login or Register
Construct 2 r90

Released Friday, May 11, 2012 at 2:01:09 PM

28mb for Windows XP, Vista & 7

Free Download
Download Manual

Coming Soon

Audio


The Audio object plays back audio files that have been imported to the project. It must be inserted to each project that needs to use audio playback. Audio files can be imported to a project by right-clicking the Sounds or Music folders in the Project Bar and selecting Import..., which brings up the Import Audio dialog. See the relevant sections for more information on the steps involved to import audio files.

Currently, audio support in browsers is patchy. Not all features may work in all browsers. For example, setting the playback rate will not work on many mobile phones. This is a problem with the browser and not Construct 2's Audio object. It is recommended to test your project in multiple browsers to identify if an issue is browser specific. However, this is an area of active development in modern browsers and the situation should improve soon.

Categorise audio files correctly


It is important to organise audio files appropriately, because audio files in the Sounds project folder are downloaded completely before playing, but files in the Music folder are streamed. This means if a Music track is accidentally put in the Sounds folder, it would have to download completely (which could take a couple of minutes) before it started playing. However, audio in the Music folder can start playing immediately since it is streamed from the server.

Audio is downloaded on demand


To speed up the loading time and start the game sooner, audio is downloaded or streamed on-demand during the game. In other words, nothing is downloaded until a Play action starts playing an audio file. Then, if the audio file is in the Music folder it starts streaming from the server; if in the Sounds folder, it starts downloading and will play when finished downloading. This also helps minimise the bandwidth requirement on the server since unused audio is never downloaded. However, it can introduce a delay before audio plays for the first time. The delay on first play is a one-off, because after the first play the sound is already downloaded and can be played immediately if played a second time.

You can also use the Preload action to start downloading an audio file without actually playing it. This can be done on Start of layout to start downloading a few important sound effects so there is no delay when they are played for the first time. However it is entirely optional (all games will work without any preloading at all), and it should not be over-used since preloading too many sound effects on startup can slow down browsers with too much downloading and result in no sound effects playing at all for a while.

Audio tags


Some actions affect audio parameters such as the volume for sounds which are already playing. However there can often be many sounds playing at once in a game. In order to identify which sounds you want to affect, sounds are played with an associated tag. This is any string that identifies the sound. For example, the player's weapon sound effect could be played with the tag "PlayerWeapon" and an enemy's weapon with the tag "EnemyWeapon". Then, the tag can be used in the Set Volume action to specify which sound to set the volume for. Tags are case insensitive.

Multiple sounds can also play at once using the same tag. In this case actions like Set Volume affect all the sounds playing with that tag.

A tag which is an empty string ("") has a special meaning: it refers only to the last sound played with the Play action. This is convenient for playing a sound and immediately setting its volume and other parameters.

Audio properties


Timescale audio
The game timescale can be used to speed up or slow down playback of the game, for effects like slow-motion. See Delta-time and framerate independence for more information. This property controls whether or not audio is affected by the game's timescale.
Off will play back audio the same regardless of the timescale.
On (sounds only) will play back audio from the Sounds project folder at a different rate depending on the timescale, but will always play back audio from the Music project folder at the same rate.
On (sounds and music) will play back all audio at a different rate depending on the timescale.
Some browsers may not support audio timescaling at all; test on multiple browsers to establish support. Also, different browsers may use different time-stretching algortihms for audio. Browsers can either alter pitch, going to lower pitch for lower time scales like a tape machine playing at a different speed; alternatively they can change the playback speed without affecting the pitch. Test on multiple browsers to establish the exact effect achieved.

Audio conditions


On ended
Triggered when a sound with a given tag finishes playing. This is not triggered for looping sounds.

Preloads complete
Since audio is downloaded on demand, audio files only start downloading when a Preload or Play action is used. This condition will be true when all audio has downloaded enough to play through to the end. This can be used to preload a set of sounds at the start of the layout, and go to the next layout when the preloads finish, eliminating any latency on the first play of sound effects.

Audio actions


Play
Play (by name)
Start playing an audio file with a given tag. The latter action gives you the opportunity to use an expression for the audio file name. The sound can optionally be set to looping when it starts playing.

Preload
Start downloading an audio file so it has no delay before playing. See the section Audio is downloaded on demand above for more information. Audio does not have to be preloaded before playing - it is optional and only serves to possibly reduce the delay before audio plays for the first time. Only two or three sounds should be preloaded at once.

Set looping
Set a sound either looping (repeating when it finishes) or not looping (stopping when it finishes). Not all browsers currently support this feature; test on multiple browsers to identify support.

Set muted
Set a sound either muted (silent) or unmuted (audible).

Set playback rate
Change the rate a sound plays back at. Different browsers may use different time-stretching algorithms (either pitch preserving or pitch altering) or not support the option at all; test in multiple browsers to identify the actual affect achieved. If the Timescale audio property is enabled, it combines with the playback rate set by this action.

Set silent
Enable, disable or toggle Silent mode. In silent mode all currently playing sounds are muted and no new sounds will play. This is useful for quickly creating an audio toggle on a title screen.

Set volume
Change the volume of a sound. The volume is given in decibels (dB). A volume of 0 dB is original volume, above 0 dB amplifies the sound, and below 0 dB attenuates the sound. For example, entering a value of -10 plays the audio back 10 dB quieter (about half as loud).

Stop
Stop a sound playing immediately.

Audio expressions


The Audio object has no expressions.

Previous Entry
Array
Next Entry
Browser

Feedback on this page
How useful was this page for you?
Do you have any suggestions for this page?