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/GameObjects/Doll",
|
||||||
"Game/Client/View/DomController",
|
"Game/Client/View/DomController",
|
||||||
"Lib/Utilities/Protocol/Helper",
|
"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) {
|
if (!window.cancelAnimationFrame) {
|
||||||
window.cancelAnimationFrame = function(id) {
|
window.cancelAnimationFrame = function(id) {
|
||||||
|
|
@ -28,6 +29,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
||||||
this.view = ViewManager.createView();
|
this.view = ViewManager.createView();
|
||||||
this.me = null;
|
this.me = null;
|
||||||
this.animationRequestId = null;
|
this.animationRequestId = null;
|
||||||
|
this.audioPlayer = null;
|
||||||
|
|
||||||
Parent.call(this, options);
|
Parent.call(this, options);
|
||||||
|
|
||||||
|
|
@ -105,6 +107,9 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
||||||
this.onSpawnPlayer(options.spawnedPlayers[i]);
|
this.onSpawnPlayer(options.spawnedPlayers[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.audioPlayer = new AudioPlayer(Settings.AUDIO_PATH + "city.mp3");
|
||||||
|
this.audioPlayer.play();
|
||||||
};
|
};
|
||||||
|
|
||||||
GameController.prototype.onWorldUpdate = function (updateData) {
|
GameController.prototype.onWorldUpdate = function (updateData) {
|
||||||
|
|
@ -266,6 +271,8 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
||||||
|
|
||||||
Parent.prototype.destroy.call(this);
|
Parent.prototype.destroy.call(this);
|
||||||
|
|
||||||
|
this.audioPlayer.destroy();
|
||||||
|
|
||||||
this.view.destroy();
|
this.view.destroy();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ define(function() {
|
||||||
GRAPHICS_SUBPATH_CHARACTERS: 'Characters/',
|
GRAPHICS_SUBPATH_CHARACTERS: 'Characters/',
|
||||||
GRAPHICS_SUBPATH_TILES: 'Tiles/',
|
GRAPHICS_SUBPATH_TILES: 'Tiles/',
|
||||||
MAPS_PATH: 'static/maps/tiled/',
|
MAPS_PATH: 'static/maps/tiled/',
|
||||||
|
AUDIO_PATH: 'static/sounds/',
|
||||||
|
|
||||||
RATIO: 21, //35
|
RATIO: 21, //35
|
||||||
// original tile size is 25 but we want it to resize to 20
|
// original tile size is 25 but we want it to resize to 20
|
||||||
|
|
|
||||||
BIN
static/sounds/city.mp3
Normal file
BIN
static/sounds/city.mp3
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue