From a50c06df5279f6095c7116b27d96998b457d8fac Mon Sep 17 00:00:00 2001 From: Joshua Anthony Date: Fri, 13 Jan 2017 16:30:24 +0100 Subject: [PATCH] Add explicit null checks to avoid falsiness of 0 for touch ids. --- SupEngine/src/Input.ts | 15 ++++++++------- .../typescript/typescriptAPI/Sup.Input.ts.txt | 8 ++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/SupEngine/src/Input.ts b/SupEngine/src/Input.ts index 212731354..69b2076c8 100644 --- a/SupEngine/src/Input.ts +++ b/SupEngine/src/Input.ts @@ -378,9 +378,9 @@ export default class Input extends EventEmitter { private onTouchStart = (event: any) => { event.preventDefault(); - if (this.touchEmulatesMouse && this.mouseTouchIdentifier == null && - this.touchesDown.length == 0 && event.changedTouches.length > 0) { - //track first touch as mouse + if (this.touchEmulatesMouse && this.mouseTouchIdentifier == null && + this.touchesDown.length === 0 && event.changedTouches.length > 0) { + // track first touch as mouse this.mouseTouchIdentifier = event.changedTouches[0].identifier; } @@ -392,7 +392,7 @@ export default class Input extends EventEmitter { } changedTouchesArray.forEach(touch => { - const touchInput: TouchState = + const touchInput: TouchState = { identifier: touch.identifier, wasStarted: true, wasEnded: false, wasMoved: false, isDown: false, position: { x: touch.clientX - rect.left, y: touch.clientY - rect.top } }; this.touches.push(touchInput); @@ -428,10 +428,10 @@ export default class Input extends EventEmitter { private onTouchMove = (event: any) => { event.preventDefault(); - + const rect = event.target.getBoundingClientRect(); const touchUpdates: any[] = []; - + for (let i = 0; i < event.changedTouches.length; i++) { const touch = event.changedTouches[i]; touchUpdates.push(touch); @@ -516,7 +516,7 @@ export default class Input extends EventEmitter { this.touchesEnded = []; this.touchesStarted = []; this.touchesMoved = []; - this.touchesDown =[]; + this.touchesDown = []; if(this.touches.length > 0) { this.touches.forEach(touch => { @@ -548,6 +548,7 @@ export default class Input extends EventEmitter { } touchesToRemove.forEach(ti => { + console.log(`Removing touch: ${ti.identifier}`); const indexToRemove = this.touches.indexOf(ti); if (indexToRemove > -1) this.touches.splice(indexToRemove, 1); }); diff --git a/plugins/default/typescript/typescriptAPI/Sup.Input.ts.txt b/plugins/default/typescript/typescriptAPI/Sup.Input.ts.txt index d5a3824d8..c5fe1dac0 100644 --- a/plugins/default/typescript/typescriptAPI/Sup.Input.ts.txt +++ b/plugins/default/typescript/typescriptAPI/Sup.Input.ts.txt @@ -69,28 +69,28 @@ namespace Sup { } export function isTouchDown(identifier?: number): boolean { - if(identifier) + if(identifier != null) return player.gameInstance.input.touchesDown.indexOf(identifier) > -1; else return player.gameInstance.input.touchesDown.length > 0; } export function wasTouchJustStarted(identifier?: number): boolean { - if(identifier) + if(identifier != null) return player.gameInstance.input.touchesStarted.indexOf(identifier) > -1; else return player.gameInstance.input.touchesStarted.length > 0; } export function wasTouchJustEnded(identifier?: number): boolean { - if(identifier) + if(identifier != null) return player.gameInstance.input.touchesEnded.indexOf(identifier) > -1; else return player.gameInstance.input.touchesEnded.length > 0; } export function wasTouchJustMoved(identifier?: number): boolean { - if(identifier) + if(identifier != null) return player.gameInstance.input.touchesMoved.indexOf(identifier) > -1; else return player.gameInstance.input.touchesMoved.length > 0;