Skip to content

Commit

Permalink
Support multiple joysticks
Browse files Browse the repository at this point in the history
Support multiple joysticks by saving the ID of the touch point when a
canvas is touched. Then when a touch is ended anywhere in the document,
each joystick compares the ended touch ID with the touch ID associated
with its canvas to know whether to honor that touch end event.
  • Loading branch information
brollin committed Jun 29, 2022
1 parent 87ff98e commit a3c6931
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions joy.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,11 @@ var JoyStick = (function(container, parameters, callback)
/**
* @desc Events for manage touch
*/
function onTouchStart(event)
let touchId = null;
function onTouchStart(event)
{
pressed = 1;
touchId = event.targetTouches[0].identifier;
}

function onTouchMove(event)
Expand Down Expand Up @@ -211,10 +213,12 @@ var JoyStick = (function(container, parameters, callback)
StickStatus.cardinalDirection = getCardinalDirection();
callback(StickStatus);
}
}
}

function onTouchEnd(event)
function onTouchEnd(event)
{
if (event.changedTouches[0].identifier !== touchId) return;

pressed = 0;
// If required reset position store variable
if(autoReturnToCenter)
Expand Down

0 comments on commit a3c6931

Please sign in to comment.