add sensitivity to touch controls
parent
013852d456
commit
45e3195d8f
|
@ -6,12 +6,18 @@
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Controls.Touch = function (
|
GameLib.D3.Controls.Touch = function (
|
||||||
graphics,
|
graphics,
|
||||||
apiControls
|
apiControls,
|
||||||
|
sensitivity
|
||||||
) {
|
) {
|
||||||
|
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(sensitivity)) {
|
||||||
|
sensitivity = 5;
|
||||||
|
}
|
||||||
|
this.sensitivity = sensitivity;
|
||||||
|
|
||||||
GameLib.D3.Controls.call(
|
GameLib.D3.Controls.call(
|
||||||
this,
|
this,
|
||||||
this.graphics,
|
this.graphics,
|
||||||
|
@ -49,7 +55,11 @@ GameLib.D3.Controls.Touch.prototype.updateInstance = function() {
|
||||||
* @returns {GameLib.D3.API.Controls}
|
* @returns {GameLib.D3.API.Controls}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Controls.Touch.prototype.toApiObject = function() {
|
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...
|
* 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(
|
return new GameLib.D3.Controls.Touch(
|
||||||
graphics,
|
graphics,
|
||||||
apiControls
|
apiControls,
|
||||||
|
objectControls.sensitivity
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
|
@ -31,6 +31,8 @@ GameLib.System.Input = function(
|
||||||
|
|
||||||
this.controlLeft = false;
|
this.controlLeft = false;
|
||||||
|
|
||||||
|
this.sensitivityCounter = 0;
|
||||||
|
|
||||||
this.renderers = [];
|
this.renderers = [];
|
||||||
this.editorControls = [];
|
this.editorControls = [];
|
||||||
this.touchControls = [];
|
this.touchControls = [];
|
||||||
|
@ -80,7 +82,7 @@ GameLib.System.Input.prototype.start = function() {
|
||||||
|
|
||||||
touchControl.domElement.instance.addEventListener(
|
touchControl.domElement.instance.addEventListener(
|
||||||
'touchmove',
|
'touchmove',
|
||||||
this.touchMove,
|
this.touchMove(touchControl),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
touchControl.domElement.instance.addEventListener(
|
touchControl.domElement.instance.addEventListener(
|
||||||
|
@ -214,6 +216,8 @@ GameLib.System.Input.prototype.onKeyboardKeyDown = function(event) {
|
||||||
|
|
||||||
GameLib.System.Input.prototype.onTouchStart = function(event) {
|
GameLib.System.Input.prototype.onTouchStart = function(event) {
|
||||||
|
|
||||||
|
this.sensitivityCounter = 0;
|
||||||
|
|
||||||
this.touches = {};
|
this.touches = {};
|
||||||
|
|
||||||
for (var t = 0; t < event.touches.length; t++) {
|
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;
|
if (this.sensitivityCounter < touchControl.sensitivity) {
|
||||||
var right = 0;
|
return;
|
||||||
var up = 0;
|
} else {
|
||||||
var down = 0;
|
this.sensitivityCounter = 0;
|
||||||
|
|
||||||
if (event.changedTouches[t].pageX > this.touches[id].pageX) {
|
|
||||||
right = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.changedTouches[t].pageX < this.touches[id].pageX) {
|
for (var t = 0; t < event.changedTouches.length; t++) {
|
||||||
left = 1;
|
|
||||||
|
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) {
|
this.touches.event = event;
|
||||||
up = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.changedTouches[t].pageY > this.touches[id].pageY) {
|
GameLib.Event.Emit(
|
||||||
down = 1;
|
GameLib.Event.TOUCH_MOVE,
|
||||||
}
|
this.touches
|
||||||
|
)
|
||||||
|
|
||||||
this.touches[id].right += right;
|
}.bind(this);
|
||||||
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
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Input.prototype.onTouchCancel = function(event) {
|
GameLib.System.Input.prototype.onTouchCancel = function(event) {
|
||||||
|
|
Loading…
Reference in New Issue