some more touch sensitivity code
parent
79f595342b
commit
af4715084f
|
@ -72,8 +72,16 @@ GameLib.System.Input.prototype.start = function() {
|
|||
*/
|
||||
if (this.touchControls.length > 0) {
|
||||
|
||||
this.touchControls.map(
|
||||
function(touchControl) {
|
||||
this.sensitivityCounter = 0;
|
||||
|
||||
if (this.touchControls.length > 1) {
|
||||
console.warn('too many touch controls - will use ' + this.touchControls[0].name)
|
||||
}
|
||||
|
||||
var touchControl = this.touchControls[0];
|
||||
|
||||
this.touchSensitivity = touchControl.sensitivity;
|
||||
|
||||
touchControl.domElement.instance.addEventListener(
|
||||
'touchstart',
|
||||
this.touchStart,
|
||||
|
@ -82,7 +90,7 @@ GameLib.System.Input.prototype.start = function() {
|
|||
|
||||
touchControl.domElement.instance.addEventListener(
|
||||
'touchmove',
|
||||
this.touchMove(touchControl),
|
||||
this.touchMove,
|
||||
false
|
||||
);
|
||||
touchControl.domElement.instance.addEventListener(
|
||||
|
@ -95,8 +103,7 @@ GameLib.System.Input.prototype.start = function() {
|
|||
this.touchCancel,
|
||||
false
|
||||
);
|
||||
}.bind(this)
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -241,22 +248,19 @@ GameLib.System.Input.prototype.onTouchStart = function(event) {
|
|||
)
|
||||
};
|
||||
|
||||
GameLib.System.Input.prototype.onTouchMove = function(touchControl) {
|
||||
|
||||
return function (event) {
|
||||
GameLib.System.Input.prototype.onTouchMove = function (event) {
|
||||
|
||||
this.sensitivityCounter++;
|
||||
|
||||
if (this.sensitivityCounter < touchControl.sensitivity) {
|
||||
|
||||
console.log(this.sensitivityCounter);
|
||||
|
||||
if (this.sensitivityCounter < this.touchSensitivity) {
|
||||
/**
|
||||
* ignore this event
|
||||
*/
|
||||
return;
|
||||
} else {
|
||||
this.sensitivityCounter = 0;
|
||||
}
|
||||
|
||||
|
||||
for (var t = 0; t < event.changedTouches.length; t++) {
|
||||
|
||||
var id = event.changedTouches[t].identifier;
|
||||
|
@ -268,18 +272,34 @@ GameLib.System.Input.prototype.onTouchMove = function(touchControl) {
|
|||
|
||||
if (event.changedTouches[t].pageX > this.touches[id].pageX) {
|
||||
right = 1;
|
||||
if (this.touches[id].left > 0) {
|
||||
this.touches[id].left = 0;
|
||||
this.sensitivityCounter = this.touchSensitivity;
|
||||
}
|
||||
}
|
||||
|
||||
if (event.changedTouches[t].pageX < this.touches[id].pageX) {
|
||||
left = 1;
|
||||
if (this.touches[id].right > 0) {
|
||||
this.touches[id].right = 0;
|
||||
this.sensitivityCounter = this.touchSensitivity;
|
||||
}
|
||||
}
|
||||
|
||||
if (event.changedTouches[t].pageY < this.touches[id].pageY) {
|
||||
up = 1;
|
||||
if (this.touches[id].down > 0) {
|
||||
this.touches[id].down = 0;
|
||||
this.sensitivityCounter = this.touchSensitivity;
|
||||
}
|
||||
}
|
||||
|
||||
if (event.changedTouches[t].pageY > this.touches[id].pageY) {
|
||||
down = 1;
|
||||
if (this.touches[id].up > 0) {
|
||||
this.touches[id].up = 0;
|
||||
this.sensitivityCounter = this.touchSensitivity;
|
||||
}
|
||||
}
|
||||
|
||||
this.touches[id].right += right;
|
||||
|
@ -295,9 +315,7 @@ GameLib.System.Input.prototype.onTouchMove = function(touchControl) {
|
|||
GameLib.Event.Emit(
|
||||
GameLib.Event.TOUCH_MOVE,
|
||||
this.touches
|
||||
)
|
||||
|
||||
}.bind(this);
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue