Skip to content
FostUK edited this page Feb 20, 2012 · 3 revisions

Sound has always been a hot topic in gameQuery. The whole idea behind gameQuery was to get rid of flash, however there isn't really a good way to implement sound support across the range of existing browsers without it. So there is a trade-off between having a pure standard javascript implementation and a mature and good supported implementation. To solve this problem gameQuery uses swappable sound plugins via the Sound Wrapper API. This allows you to code your games without thinking about the sound backend and later choose the preferred implementation. You can even switch the implementation later, for example you can start with a flash based implementation (like the SoundManager wrapper) and switch to the HTML5 base implementation when more browser supports it.

Three implementations are provided: an HTML 5 one, a SoundManager one and an empty one. The most stable is obviously the SoundManager wrapper. The HTML 5 wrapper is still in development and since HML5 specifications are not finished it is still evolving. The empty one ("bogus") is there as a starting point for the development of your own wrapper. If you've developed your own wrapper don't hesitate to share it, I'll gladly put it on this site.

A sound wrapper is in fact a sound object with a series of conventional functions. Any object that corresponds to this convention can be used as sound wrapper, you can find the description of those functions in the $.gameQuery.Sound Object section bellow.

##The SoundManager 2 sound wrapper To use this wrapper you will have to add to your page [SoundManager 2] (http://www.schillmania.com/projects/soundmanager2/); that is the javascript library as well as the swf file. You also have to include the javascript files in the correct order:

<script type="text/javascript" src="./jquery.js"></script>
<script type="text/javascript" src="./soundmanager2.js"></script>
<script type="text/javascript" src="./jquery.gamequery.js"></script>
<script type="text/javascript" src="./jquery.gamequery.soundwrapper.soundmanager2.js"></script>
<script type="text/javascript" src="./your.game.js"></script>

##The HTML5 Sound Wrapper To use the HTML5 sound wrapper you just need to add the script to your page. It has to be added after the gameQuery script. There is no other requirement but keep in mind that this will be compatible only with the browser supporting the HTML5 audio object.

##The $.gameQuery.Sound Object Except for the constructor, the methods of this object are of interest only to people developing their own wrapper.

###SoundWrapper(url, loop) The constructor, it take the url of the sound and a boolean to indicate if the sound should be looped or not.

###play() This function should start the playing of the sound.

###pause() This function should pause the sound. After a call to this function a successive call to play() should play the sound from the position it where paused.

###stop() This function should stop the sound. After a call to this function a succesive call to play() should play the sound from the start.

###muted(mute) If true is passed, this function should mute the sound without pausing or stopping it. If false is passed it should unmute the sound.

###ready() This function returns true if the sound is ready to be played, false otherwise.