| 1 | //<DOC> category GameAudio |
| 2 | |
| 3 | var GameAudio = |
| 4 | { |
| 5 | active: false, |
| 6 | |
| 7 | //<DOC> <function> GameAudio.init(collection, containingFolder)<br><br>Starts the audio system, using an array of audio names 'collection' and a path 'containingFolder' in which the sounds can be found. Do not include file extentions in sound names! |
| 8 | init: function(collection, containingFolder) |
| 9 | { |
| 10 | console.log("GAME: Loading sounds. (Note: Only supported from online-source, will fail when executed on local files.)"); |
| 11 | |
| 12 | try |
| 13 | { |
| 14 | var soundColl = []; |
| 15 | |
| 16 | for(var i = 0; i < collection.length; i++) |
| 17 | { |
| 18 | collection[i].preload = true; |
| 19 | |
| 20 | soundColl.push(collection[i]); |
| 21 | } |
| 22 | |
| 23 | if(containingFolder == null) |
| 24 | containingFolder = ""; |
| 25 | |
| 26 | if(containingFolder != "") |
| 27 | containingFolder += "/"; |
| 28 | |
| 29 | ion.sound |
| 30 | ({ |
| 31 | sounds: soundColl, |
| 32 | volume: 1, |
| 33 | preload: true, |
| 34 | multiplay: true, |
| 35 | path: containingFolder |
| 36 | }); |
| 37 | |
| 38 | this.active = true; |
| 39 | } |
| 40 | catch(err) |
| 41 | { |
| 42 | console.log("GAME: ERROR: Sounds could not be loaded. Sound will not be available."); |
| 43 | } |
| 44 | }, |
| 45 | |
| 46 | //<DOC> <function> GameAudio.play(name)<br><br>plays a sound with the name 'name'. |
| 47 | play: function(name) |
| 48 | { |
| 49 | if(this.active) |
| 50 | ion.sound.play(name); |
| 51 | } |
| 52 | } |