diff --git a/src/game-lib-d3-controls-touch.js b/src/game-lib-d3-controls-touch.js index c4ada48..dd310f3 100644 --- a/src/game-lib-d3-controls-touch.js +++ b/src/game-lib-d3-controls-touch.js @@ -6,12 +6,18 @@ */ GameLib.D3.Controls.Touch = function ( graphics, - apiControls + apiControls, + sensitivity ) { this.graphics = graphics; this.graphics.isNotThreeThrow(); + if (GameLib.Utils.UndefinedOrNull(sensitivity)) { + sensitivity = 5; + } + this.sensitivity = sensitivity; + GameLib.D3.Controls.call( this, this.graphics, @@ -49,7 +55,11 @@ GameLib.D3.Controls.Touch.prototype.updateInstance = function() { * @returns {GameLib.D3.API.Controls} */ GameLib.D3.Controls.Touch.prototype.toApiObject = function() { - var apiControls = GameLib.D3.Controls.prototype.toApiObject.call(this); + + var apiControls = GameLib.D3.Controls.prototype.toApiObject.call(this); + + apiControls.sensitivity = this.sensitivity; + /** * add other properties here as this component develops... */ @@ -69,7 +79,8 @@ GameLib.D3.Controls.Touch.FromObject = function(graphics, objectControls) { return new GameLib.D3.Controls.Touch( graphics, - apiControls + apiControls, + objectControls.sensitivity ); }; \ No newline at end of file diff --git a/src/game-lib-system-input.js b/src/game-lib-system-input.js index 5cb2c5b..bcecdc6 100644 --- a/src/game-lib-system-input.js +++ b/src/game-lib-system-input.js @@ -31,6 +31,8 @@ GameLib.System.Input = function( this.controlLeft = false; + this.sensitivityCounter = 0; + this.renderers = []; this.editorControls = []; this.touchControls = []; @@ -80,7 +82,7 @@ GameLib.System.Input.prototype.start = function() { touchControl.domElement.instance.addEventListener( 'touchmove', - this.touchMove, + this.touchMove(touchControl), false ); touchControl.domElement.instance.addEventListener( @@ -214,6 +216,8 @@ GameLib.System.Input.prototype.onKeyboardKeyDown = function(event) { GameLib.System.Input.prototype.onTouchStart = function(event) { + this.sensitivityCounter = 0; + this.touches = {}; for (var t = 0; t < event.touches.length; t++) { @@ -237,47 +241,60 @@ GameLib.System.Input.prototype.onTouchStart = function(event) { ) }; -GameLib.System.Input.prototype.onTouchMove = function(event) { +GameLib.System.Input.prototype.onTouchMove = function(touchControl) { - for (var t = 0; t < event.changedTouches.length; t++) { + return function (event) { - var id = event.changedTouches[t].identifier; + this.sensitivityCounter++; - var left = 0; - var right = 0; - var up = 0; - var down = 0; - - if (event.changedTouches[t].pageX > this.touches[id].pageX) { - right = 1; + if (this.sensitivityCounter < touchControl.sensitivity) { + return; + } else { + this.sensitivityCounter = 0; } - if (event.changedTouches[t].pageX < this.touches[id].pageX) { - left = 1; + for (var t = 0; t < event.changedTouches.length; t++) { + + var id = event.changedTouches[t].identifier; + + var left = 0; + var right = 0; + var up = 0; + var down = 0; + + if (event.changedTouches[t].pageX > this.touches[id].pageX) { + right = 1; + } + + if (event.changedTouches[t].pageX < this.touches[id].pageX) { + left = 1; + } + + if (event.changedTouches[t].pageY < this.touches[id].pageY) { + up = 1; + } + + if (event.changedTouches[t].pageY > this.touches[id].pageY) { + down = 1; + } + + this.touches[id].right += right; + this.touches[id].left += left; + this.touches[id].up += up; + this.touches[id].down += down; + this.touches[id].pageX = event.changedTouches[t].pageX; + this.touches[id].pageY = event.changedTouches[t].pageY; } - if (event.changedTouches[t].pageY < this.touches[id].pageY) { - up = 1; - } + this.touches.event = event; - if (event.changedTouches[t].pageY > this.touches[id].pageY) { - down = 1; - } + GameLib.Event.Emit( + GameLib.Event.TOUCH_MOVE, + this.touches + ) - this.touches[id].right += right; - this.touches[id].left += left; - this.touches[id].up += up; - this.touches[id].down += down; - this.touches[id].pageX = event.changedTouches[t].pageX; - this.touches[id].pageY = event.changedTouches[t].pageY; - } + }.bind(this); - this.touches.event = event; - - GameLib.Event.Emit( - GameLib.Event.TOUCH_MOVE, - this.touches - ) }; GameLib.System.Input.prototype.onTouchCancel = function(event) {