some more touch sensitivity code
parent
79f595342b
commit
af4715084f
|
@ -72,31 +72,38 @@ GameLib.System.Input.prototype.start = function() {
|
||||||
*/
|
*/
|
||||||
if (this.touchControls.length > 0) {
|
if (this.touchControls.length > 0) {
|
||||||
|
|
||||||
this.touchControls.map(
|
this.sensitivityCounter = 0;
|
||||||
function(touchControl) {
|
|
||||||
touchControl.domElement.instance.addEventListener(
|
if (this.touchControls.length > 1) {
|
||||||
'touchstart',
|
console.warn('too many touch controls - will use ' + this.touchControls[0].name)
|
||||||
this.touchStart,
|
}
|
||||||
false
|
|
||||||
);
|
var touchControl = this.touchControls[0];
|
||||||
|
|
||||||
|
this.touchSensitivity = touchControl.sensitivity;
|
||||||
|
|
||||||
|
touchControl.domElement.instance.addEventListener(
|
||||||
|
'touchstart',
|
||||||
|
this.touchStart,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
touchControl.domElement.instance.addEventListener(
|
||||||
|
'touchmove',
|
||||||
|
this.touchMove,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
touchControl.domElement.instance.addEventListener(
|
||||||
|
'touchend',
|
||||||
|
this.touchEnd,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
touchControl.domElement.instance.addEventListener(
|
||||||
|
'touchcancel',
|
||||||
|
this.touchCancel,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
touchControl.domElement.instance.addEventListener(
|
|
||||||
'touchmove',
|
|
||||||
this.touchMove(touchControl),
|
|
||||||
false
|
|
||||||
);
|
|
||||||
touchControl.domElement.instance.addEventListener(
|
|
||||||
'touchend',
|
|
||||||
this.touchEnd,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
touchControl.domElement.instance.addEventListener(
|
|
||||||
'touchcancel',
|
|
||||||
this.touchCancel,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
}.bind(this)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -241,63 +248,74 @@ GameLib.System.Input.prototype.onTouchStart = function(event) {
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Input.prototype.onTouchMove = function(touchControl) {
|
GameLib.System.Input.prototype.onTouchMove = function (event) {
|
||||||
|
|
||||||
return function (event) {
|
this.sensitivityCounter++;
|
||||||
|
|
||||||
this.sensitivityCounter++;
|
if (this.sensitivityCounter < this.touchSensitivity) {
|
||||||
|
/**
|
||||||
|
* ignore this event
|
||||||
|
*/
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
this.sensitivityCounter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.sensitivityCounter < touchControl.sensitivity) {
|
for (var t = 0; t < event.changedTouches.length; t++) {
|
||||||
|
|
||||||
console.log(this.sensitivityCounter);
|
var id = event.changedTouches[t].identifier;
|
||||||
|
|
||||||
return;
|
var left = 0;
|
||||||
} else {
|
var right = 0;
|
||||||
this.sensitivityCounter = 0;
|
var up = 0;
|
||||||
|
var down = 0;
|
||||||
|
|
||||||
|
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) {
|
||||||
for (var t = 0; t < event.changedTouches.length; t++) {
|
left = 1;
|
||||||
|
if (this.touches[id].right > 0) {
|
||||||
var id = event.changedTouches[t].identifier;
|
this.touches[id].right = 0;
|
||||||
|
this.sensitivityCounter = this.touchSensitivity;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.touches.event = event;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.Event.Emit(
|
if (event.changedTouches[t].pageY > this.touches[id].pageY) {
|
||||||
GameLib.Event.TOUCH_MOVE,
|
down = 1;
|
||||||
this.touches
|
if (this.touches[id].up > 0) {
|
||||||
)
|
this.touches[id].up = 0;
|
||||||
|
this.sensitivityCounter = this.touchSensitivity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}.bind(this);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.touches.event = event;
|
||||||
|
|
||||||
|
GameLib.Event.Emit(
|
||||||
|
GameLib.Event.TOUCH_MOVE,
|
||||||
|
this.touches
|
||||||
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue