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,7 +241,17 @@ GameLib.System.Input.prototype.onTouchStart = function(event) {
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Input.prototype.onTouchMove = function(event) {
|
GameLib.System.Input.prototype.onTouchMove = function(touchControl) {
|
||||||
|
|
||||||
|
return function (event) {
|
||||||
|
|
||||||
|
this.sensitivityCounter++;
|
||||||
|
|
||||||
|
if (this.sensitivityCounter < touchControl.sensitivity) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
this.sensitivityCounter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
for (var t = 0; t < event.changedTouches.length; t++) {
|
for (var t = 0; t < event.changedTouches.length; t++) {
|
||||||
|
|
||||||
|
@ -278,6 +292,9 @@ GameLib.System.Input.prototype.onTouchMove = function(event) {
|
||||||
GameLib.Event.TOUCH_MOVE,
|
GameLib.Event.TOUCH_MOVE,
|
||||||
this.touches
|
this.touches
|
||||||
)
|
)
|
||||||
|
|
||||||
|
}.bind(this);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Input.prototype.onTouchCancel = function(event) {
|
GameLib.System.Input.prototype.onTouchCancel = function(event) {
|
||||||
|
|
Loading…
Reference in New Issue