From 9ecf5e2895fdb8aaaf5e33c714df418833308fa8 Mon Sep 17 00:00:00 2001 From: Eemeli Kelokorpi Date: Wed, 2 Apr 2014 15:57:03 +0300 Subject: [PATCH] Added multitouch support --- src/engine/core.js | 2 +- src/engine/renderer.js | 32 ++++++++++++-------------------- src/game/main.js | 2 +- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/engine/core.js b/src/engine/core.js index cf67eb4b..b3695051 100755 --- a/src/engine/core.js +++ b/src/engine/core.js @@ -26,7 +26,7 @@ if(typeof(global) !== 'undefined' && global.game) return; @class Core **/ var core = { - version: '1.2.1', + version: '1.3.0', config: window.pandaConfig || {}, /** Scale factor for Retina and HiRes mode. diff --git a/src/engine/renderer.js b/src/engine/renderer.js index 0f6c7042..79032351 100755 --- a/src/engine/renderer.js +++ b/src/engine/renderer.js @@ -3659,14 +3659,12 @@ PIXI.InteractionManager.prototype.onTouchMove = function(event) touchData.global.x = touchEvent.clientX; touchData.global.y = touchEvent.clientY; } - } - var length = this.interactiveItems.length; - for (i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - if(item.touchmove) - item.touchmove(touchData); + for (var j = 0; j < this.interactiveItems.length; j++) + { + var item = this.interactiveItems[j]; + if(item.touchmove && item.__touchDatas[touchEvent.identifier]) item.touchmove(touchData); + } } }; @@ -3716,7 +3714,8 @@ PIXI.InteractionManager.prototype.onTouchStart = function(event) //call the function! if(item.touchstart)item.touchstart(touchData); item.__isDown = true; - item.__touchData = touchData; + item.__touchDatas = item.__touchDatas || {}; + item.__touchDatas[touchEvent.identifier] = touchData; if(!item.interactiveChildren)break; } @@ -3754,11 +3753,11 @@ PIXI.InteractionManager.prototype.onTouchEnd = function(event) for (var j = 0; j < length; j++) { var item = this.interactiveItems[j]; - var itemTouchData = item.__touchData; // <-- Here! - item.__hit = this.hitTest(item, touchData); - if(itemTouchData === touchData) - { + if(item.__touchDatas[touchEvent.identifier]) { + + item.__hit = this.hitTest(item, item.__touchDatas[touchEvent.identifier]); + // so this one WAS down... touchData.originalEvent = event || window.event; // hitTest?? @@ -3786,15 +3785,8 @@ PIXI.InteractionManager.prototype.onTouchEnd = function(event) item.__isDown = false; } - item.__touchData = null; - - } - /* - else - { - + item.__touchDatas[touchEvent.identifier] = null; } - */ } // remove the touch.. this.pool.push(touchData); diff --git a/src/game/main.js b/src/game/main.js index 5fbc36c9..23dec174 100755 --- a/src/game/main.js +++ b/src/game/main.js @@ -6,7 +6,7 @@ game.module( game.addAsset('logo.png'); SceneGame = game.Scene.extend({ - backgroundColor: 0x808080, + backgroundColor: 0xb9bec7, init: function() { var logo = new game.Sprite('logo.png');