Skip to content
This repository has been archived by the owner on Mar 5, 2021. It is now read-only.

Commit

Permalink
Add explicit null checks to avoid falsiness of 0 for touch ids.
Browse files Browse the repository at this point in the history
  • Loading branch information
AgileJoshua committed Jan 13, 2017
1 parent eb23ff3 commit a50c06d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
15 changes: 8 additions & 7 deletions SupEngine/src/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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);
});
Expand Down
8 changes: 4 additions & 4 deletions plugins/default/typescript/typescriptAPI/Sup.Input.ts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a50c06d

Please sign in to comment.