On mobile, I’m pausing the game when the app becomes inactive, e.g when the user swipes from the edge, triggering the task switcher. The problem is, I can’t “release” the joystick programmatically. This means the character resumes walking after unpausing, even though the joystick is not pressed.
The easiest way to release the joystick seems to be to send a pointerup
event to its canvas, but it requires a valid pointerId
property. I wrote this disgusting hack as proof-of-concept:
class MyController {
constructor() {
this.leftPad = new VirtualJoystick(...)
}
pause() {
// Release the joystick. This requires sending a 'touchup' event, _with a valid pointerId_.
// There should be a method on `VirtualJoystick` to allow this.
let touches = (<any>this.leftPad)._touches as StringDictionary<{ x: number; y: number; prevX: number; prevY: number } | PointerEvent>
touches.forEach((key, value) => {
console.log(key, value)
VirtualJoystick.Canvas!.dispatchEvent(new PointerEvent('pointerup', <any>{pointerId: key}))
})
}
}
I wanted to get some feedback before spending time making a PR.