Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

New sound framework.

  • Loading branch information...
commit 0a43a80fb6686952f24fd7451df8617dfbbe8a23 1 parent 646dead
@apendleton apendleton authored
Showing with 43 additions and 5 deletions.
  1. +2 −1  .gitignore
  2. +31 −3 dreamcast2.js
  3. +8 −0 index.html
  4. +2 −1  requirements.txt
View
3  .gitignore
@@ -1,3 +1,4 @@
.gitmodules
jquery-svg
-svgweb
+svgweb
+SoundManager2
View
34 dreamcast2.js
@@ -49,7 +49,8 @@ if (window.log === undefined) {
'frameRate': 30, /* set to zero for fast-as-possible display */
'uuid': (new Date()).getTime(),
'masks': [],
- 'preload': null
+ 'preload': null,
+ 'soundMode': typeof(soundManager) != 'undefined' ? 'sm2' : 'html5'
}, options);
this.intervalRate = this.frameRate ? 1000 / this.frameRate : 0;
@@ -58,6 +59,10 @@ if (window.log === undefined) {
this.elapsed = 0;
this.elem = $(sel);
+
+ this.preloadSounds = this['_' + this.soundMode + 'PreloadSounds'];
+ this.playSound = this['_' + this.soundMode + 'PlaySound'];
+ console.log(this.soundMode);
var game = this;
this.elem.css({'width': this.width, 'height': this.height}).svg(function(svg) {
@@ -180,18 +185,41 @@ if (window.log === undefined) {
}
return id;
};
- Game.prototype.preloadSounds = function(sounds) {
+
+ Game.prototype._html5PreloadSounds = function(sounds) {
$.each(sounds, function(name, file) {
var id = 'sound-' + name;
$('body').append('<audio src="' + file +'.wav" autobuffer="autobuffer" preload="auto" id="' + id + '" />');
})
}
- Game.prototype.playSound = function(sound) {
+ Game.prototype._html5PlaySound = function(sound) {
var snd = new Audio($('#sound-' + sound).attr('src'));
snd.play();
return snd;
}
+ Game.prototype._sm2PreloadSounds = function(sounds) {
+ soundManager.onready(function() {
+ $.each(sounds, function(name, file) {
+ soundManager.createSound({
+ id: name,
+ url: file + '.mp3',
+ autoLoad: true,
+ multiShotEvents: true
+ });
+ });
+ })
+ }
+
+ Game.prototype._sm2PlaySound = function(sound) {
+ var out = {'ended': false}
+ var snd = soundManager.play(sound, {onfinish: function() {
+ out.ended = true;
+ }});
+ out.pause = function() { snd.pause(); };
+ return out;
+ }
+
dreamcast2.Game = Game;
/*** game scene ***/
View
8 index.html
@@ -19,6 +19,14 @@
<script src="jquery-1.4.2.min.js"></script>
<script src="jquery-svg/jquery.svg.js"></script>
<script src="jquery-svg/jquery.svgdom.js"></script>
+
+ <script src="SoundManager2/script/soundmanager2.js"></script>
+ <script>
+ soundManager.url = "SoundManager2/swf/";
+ soundManager.flashVersion = 9;
+ soundManager.debugMode = false;
+ </script>
+
<script src="dreamcast2.js"></script>
<script src="capdefense.js"></script>
<script>
View
3  requirements.txt
@@ -1,2 +1,3 @@
https://github.com/apendleton/jquery-svg.git
-https://github.com/apendleton/svgweb.git
+https://github.com/apendleton/svgweb.git
+https://github.com/scottschiller/SoundManager2.git
Please sign in to comment.
Something went wrong with that request. Please try again.