BlueGit

timfa frameworkv3

Files

frameworkv3 / audio.js

audio.js

Initial Commit
timfa Tim Falken · pushed by timfa · 10 years ago
d075adff History
audio.js 1.2 KiB Download Raw
1//<DOC> category GameAudio
2
3var 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 soundColl.push({name: collection[i], preload: true});
19 }
20
21 if(containingFolder == null)
22 containingFolder = "";
23
24 if(containingFolder != "")
25 containingFolder += "/";
26
27 ion.sound
28 ({
29 sounds: soundColl,
30 volume: 1,
31 preload: true,
32 multiplay: true,
33 path: containingFolder
34 });
35
36 this.active = true;
37 }
38 catch(err)
39 {
40 console.log("GAME: ERROR: Sounds could not be loaded. Sound will not be available.");
41 }
42 },
43
44 //<DOC> <function> GameAudio.play(name)<br><br>plays a sound with the name 'name'.
45 play: function(name)
46 {
47 if(this.active)
48 ion.sound.play(name);
49 }
50}