stop all audio, package.json

beta.r3js.org
-=yb4f310 2017-11-19 14:26:32 +01:00
parent 2681e8d011
commit 2959d9a62e
4 changed files with 63 additions and 40 deletions

View File

@ -1,6 +1,6 @@
{
"name": "gamewheel-game-lib",
"description": "Gamewheel Game Library",
"name": "game-lib",
"description": "Game Library",
"version": "1.0.0",
"dependencies": {
"cannon": "^0.6.2",
@ -18,7 +18,7 @@
"three": "*",
"through2": "^2.0.1"
},
"repository": "https://github.com/ToywheelDev/game-lib.git",
"repository": "https://bitbucket.org/flyingspoon/editor-game-lib",
"license": "UNLICENSED",
"devDependencies": {
"chai": "^3.5.0",

View File

@ -101,7 +101,7 @@ GameLib.Event.GET_SCENE = 0x53;
GameLib.Event.CUSTOM_CODE_WINDOW_RESIZE = 0x54;
GameLib.Event.LOAD_FONT = 0x55;
GameLib.Event.FONT_NOT_FOUND = 0x56;
//GameLib.Event.FONT_INSTANCE_CREATED = 0x57;
GameLib.Event.STOP_ALL_AUDIO = 0x57;
GameLib.Event.REGISTER_DEPENDENCIES = 0x58;
GameLib.Event.GAME_LOADED = 0x59;
GameLib.Event.GAME_RESTART = 0x5a;
@ -208,7 +208,7 @@ GameLib.Event.GetEventName = function(number) {
case 0x54 : return 'custom_code_window_resize';
case 0x55 : return 'load_font';
case 0x56 : return 'font_not_found';
case 0x57 : return 'unused';//'font_instance_created';
case 0x57 : return 'stop_all_audio';
case 0x58 : return 'register_dependencies';
case 0x59 : return 'game_loaded';
case 0x5a : return 'game_restart';

View File

@ -21,6 +21,8 @@ GameLib.System.Audio = function(
this.stopAudioSubscription = null;
this.stopAllAudioSubscription = null;
this.audioComponents = [];
this.toPlay = [];
@ -61,6 +63,11 @@ GameLib.System.Audio.prototype.start = function() {
this.stopAudio.bind(this)
);
this.stopAllAudioSubscription = GameLib.Event.Subscribe(
GameLib.Event.STOP_ALL_AUDIO,
this.stopAllAudio.bind(this)
);
};
/**
@ -108,8 +115,6 @@ GameLib.System.Audio.prototype.playAudio = function(data) {
if (!audio.instance.isPlaying) {
console.log('playing audio : ' + audio.name);
audio.instance.play();
audio.instance.onEnded = function() {
@ -132,7 +137,7 @@ GameLib.System.Audio.prototype.playAudio = function(data) {
/**
* This audio still has to load
*/
console.log('delaying play until loaded for: ' + data.name);
console.log('delaying audio play until loaded for: ' + data.name);
this.toPlay.push(data.name);
}
};
@ -141,6 +146,16 @@ GameLib.System.Audio.prototype.pauseAudio = function(data) {
};
GameLib.System.Audio.prototype.stopAllAudio = function(data) {
this.audioComponents.map(
function(audio) {
if (audio.instance.isPlaying) {
audio.instance.stop();
}
}
)
};
GameLib.System.Audio.prototype.stopAudio = function(data) {
this.audioComponents.map(
@ -172,5 +187,6 @@ GameLib.System.Audio.prototype.stop = function() {
this.playAudioSubscription.remove();
this.pauseAudioSubscription.remove();
this.stopAudioSubscription.remove();
this.stopAllAudioSubscription.remove();
};

View File

@ -611,52 +611,59 @@ GameLib.System.Input.prototype.onTouchMove = function (event) {
var id = null;
for (var t = 0; t < event.changedTouches.length; t++) {
var leftTouch = null;
var rightTouch = null;
id = event.changedTouches[t].identifier;
if (event.changedTouches.length === 2) {
if (this.touches[id]) {
}
var diffX = Math.abs(this.touches[id].lastTouchX - event.changedTouches[t].pageX);
var diffY = Math.abs(this.touches[id].lastTouchY - event.changedTouches[t].pageY);
for (var t = 0; t < event.changedTouches.length; t++) {
var left = 0;
var right = 0;
var up = 0;
var down = 0;
id = event.changedTouches[t].identifier;
if (this.touches[id].lastTouchX < event.changedTouches[t].pageX) {
right += diffX;
}
if (this.touches[id]) {
if (this.touches[id].lastTouchX > event.changedTouches[t].pageX) {
left += diffX;
}
var diffX = Math.abs(this.touches[id].lastTouchX - event.changedTouches[t].pageX);
var diffY = Math.abs(this.touches[id].lastTouchY - event.changedTouches[t].pageY);
if (this.touches[id].lastTouchY > event.changedTouches[t].pageY) {
up += diffY;
}
var left = 0;
var right = 0;
var up = 0;
var down = 0;
if (this.touches[id].lastTouchY < event.changedTouches[t].pageY) {
down += diffY;
}
this.touches[id].right = right;
this.touches[id].left = left;
this.touches[id].up = up;
this.touches[id].down = down;
this.touches[id].lastTouchX = event.changedTouches[t].pageX;
this.touches[id].lastTouchY = event.changedTouches[t].pageY;
this.touches[id].pageX = event.changedTouches[t].pageX;
this.touches[id].pageY = event.changedTouches[t].pageY;
if (this.touches[id].lastTouchX < event.changedTouches[t].pageX) {
right += diffX;
}
if (this.touches[id].lastTouchX > event.changedTouches[t].pageX) {
left += diffX;
}
if (this.touches[id].lastTouchY > event.changedTouches[t].pageY) {
up += diffY;
}
//console.log(this.touches[id]);
if (this.touches[id].lastTouchY < event.changedTouches[t].pageY) {
down += diffY;
}
this.touches[id].right = right;
this.touches[id].left = left;
this.touches[id].up = up;
this.touches[id].down = down;
this.touches[id].lastTouchX = event.changedTouches[t].pageX;
this.touches[id].lastTouchY = event.changedTouches[t].pageY;
this.touches[id].pageX = event.changedTouches[t].pageX;
this.touches[id].pageY = event.changedTouches[t].pageY;
}
this.touches.event = event;
//console.log(this.touches[id]);
}
this.touches.event = event;
if (this.sensitivityCounter >= this.touchSensitivity) {