Game Development Reference
In-Depth Information
referenced function with
// the keyword 'new'. This style co function
creation essentially
// makes the function behave like a
constructor, which allows us to
// simulate classes in JavaScript
var SoundFx = function() {
// Every sound entity will be stored here for
future use
var sounds = {};
//
------------------------------------------------------------
// Register a new sound entity with some
basic configurations
//
------------------------------------------------------------
function addSound(name, file, loop, autoplay)
{
// Don't create two entities with the same
name
if (sounds[name] instanceof Audio)
return false;
// Behold, the new HTML5 Audio element!
sounds[name] = new Audio();
sounds[name].src = file;
sounds[name].controls = false;
sounds[name].loop = loop;
sounds[name].autoplay = autoplay;
}
//
-----------------------------------------------------------
// Play a file from the beginning, even if
it's already playing
//
Search WWH ::




Custom Search