Mark Andrade

astro clash covere tile. It says Astro clash blue on dark blue with the hero icon showing.

Phaser touch events firing twice

Testing the games out on iPhone I’m encountering that I touch the bottom of the screen a lot. Outside of the canvas.

The game is centered vertically and the canvas does not stretch to the size of the screen. If I touch outside the canvas the game does not register touches.

I either have to catch and send the event to the canvas or just move the game to the bottom of the screen. I really don’t want to move it.

(some time passes)

OR… RTFM… “pointerdownoutside” event! Although it didn’t work as expected on the phone when testing.

Turns out touch AND pointer events are fired on mobile when a touch is registered. This causes my callback code to be called twice. Frustrating.

Have to check if the game is running on mobile AND the event is NOT a touch and break out of the callback function.

if (theInputEvent.wasTouch == false && isMobile == true) {
	  return;
 }

This fix is all thanks to William and his Phaser touch events firing twice article.