Namespace

Sound

Sound

Methods

# isPlaying(id) → {boolean}

Checks if a sound with the asset id is currently playing.
Parameters:
Name Type Description
id string Id of the sound asset to check for.

View Source rpgcode.js, line 1948

whether or not the sound is playing
boolean
Example
var playing = rpgcode.isPlaying("rain");
rpgcode.log(playing);

# playSound(id, loop, volumeopt) → {Object}

Plays the supplied sound file, up to five sound channels can be active at once.
Parameters:
Name Type Attributes Default Description
id string Id of the sound asset to play.
loop boolean Should it loop indefinitely?
volume number <optional>
1.0 Value ranging from 1.0 to 0.0, default is 1.0 (i.e. 100%).

View Source rpgcode.js, line 2148

A HTML5 audio element representing the playing sound.
Object
Example
// Game assets used in this program.
var assets = {
 "audio": {
     "intro": "intro.mp3"
 }
};

// Load up the assets we need
rpgcode.loadAssets(assets, function () {
 // The sound file is loaded play it in an infinite loop.
 rpgcode.playSound("intro", true);
}); 

# stopSound(file)

Stop playing a specific sound file, if no file is set stop all sounds.
Parameters:
Name Type Description
file string The relative path of the sound file to stop.

View Source rpgcode.js, line 3333

Example
rpgcode.stopSound("intro");