diff --git a/package.json b/package.json index bbd24b3..a77547d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/game-lib-a-1-event.js b/src/game-lib-a-1-event.js index 27d58a8..20ca8e2 100644 --- a/src/game-lib-a-1-event.js +++ b/src/game-lib-a-1-event.js @@ -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'; diff --git a/src/game-lib-system-audio.js b/src/game-lib-system-audio.js index 97e8b7f..0325929 100644 --- a/src/game-lib-system-audio.js +++ b/src/game-lib-system-audio.js @@ -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(); }; diff --git a/src/game-lib-system-input.js b/src/game-lib-system-input.js index 5d77617..fa79cbe 100644 --- a/src/game-lib-system-input.js +++ b/src/game-lib-system-input.js @@ -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) {