mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
first stab at background audio
This commit is contained in:
parent
1a71fa38f9
commit
1bdc798540
4 changed files with 46 additions and 2 deletions
36
app/Game/Client/AudioPlayer.js
Normal file
36
app/Game/Client/AudioPlayer.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
define([
|
||||
],
|
||||
|
||||
function () {
|
||||
|
||||
function AudioPlayer(path) {
|
||||
this.audio = new Audio(path);
|
||||
this.audio.loop = true;
|
||||
this.audio.volume = 0.1;
|
||||
|
||||
this.audio.addEventListener('timeupdate', function(){
|
||||
var buffer = 1
|
||||
if(this.currentTime > this.duration - buffer) {
|
||||
this.currentTime = 1
|
||||
this.play()
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
|
||||
AudioPlayer.prototype.play = function() {
|
||||
this.audio.play();
|
||||
this.doPlay = true;
|
||||
}
|
||||
|
||||
AudioPlayer.prototype.stop = function() {
|
||||
this.audio.stop();
|
||||
this.doPlay = false;
|
||||
};
|
||||
|
||||
AudioPlayer.prototype.destroy = function() {
|
||||
this.stop();
|
||||
};
|
||||
|
||||
return AudioPlayer;
|
||||
|
||||
});
|
||||
|
|
@ -11,10 +11,11 @@ define([
|
|||
"Game/Client/GameObjects/Doll",
|
||||
"Game/Client/View/DomController",
|
||||
"Lib/Utilities/Protocol/Helper",
|
||||
"Game/Client/Me"
|
||||
"Game/Client/Me",
|
||||
"Game/Client/AudioPlayer"
|
||||
],
|
||||
|
||||
function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, requestAnimFrame, Settings, GameObject, Doll, DomController, ProtocolHelper, Me) {
|
||||
function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, requestAnimFrame, Settings, GameObject, Doll, DomController, ProtocolHelper, Me, AudioPlayer) {
|
||||
|
||||
if (!window.cancelAnimationFrame) {
|
||||
window.cancelAnimationFrame = function(id) {
|
||||
|
|
@ -28,6 +29,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
|||
this.view = ViewManager.createView();
|
||||
this.me = null;
|
||||
this.animationRequestId = null;
|
||||
this.audioPlayer = null;
|
||||
|
||||
Parent.call(this, options);
|
||||
|
||||
|
|
@ -105,6 +107,9 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
|||
this.onSpawnPlayer(options.spawnedPlayers[i]);
|
||||
}
|
||||
}
|
||||
|
||||
this.audioPlayer = new AudioPlayer(Settings.AUDIO_PATH + "city.mp3");
|
||||
this.audioPlayer.play();
|
||||
};
|
||||
|
||||
GameController.prototype.onWorldUpdate = function (updateData) {
|
||||
|
|
@ -266,6 +271,8 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
|||
|
||||
Parent.prototype.destroy.call(this);
|
||||
|
||||
this.audioPlayer.destroy();
|
||||
|
||||
this.view.destroy();
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue