Phaser: Touch input isn't working on touch devices

Created on 18 Nov 2018  路  5Comments  路  Source: photonstorm/phaser

Version

  • Phaser Version: 3.14.0~3.15.1
  • Operating system: Android, iOS (possibly for all devices with touch support)
  • Browser: N/A

Description

When I was working on my mobile game, my testers found out that its touch control didn't work. After my investigation, I discovered that the pointer/touch input just dosen't work on the first scene using mobile devices. All of the scenes after work perfectly fine. Also, if I load some web fonts inside the create() function of the scene, there will be a short period of time that the touch input will work.

Example Test Code

Test code on CodePen

Additional Information

Most helpful comment

The problem is the assignment of activePointer to a local property, which you then check in the update loop. The activePointer is not set on a touch device until you actually touch it, so you're basically binding and checking the mouse pointer (which doesn't do anything on mobile) in your code.

Swap the code in your Scene 1 update loop so it says: this.input.activePointer.isDown and it'll start doing as you expect. Once the scene has been touched, anyway.

All 5 comments

The problem is the assignment of activePointer to a local property, which you then check in the update loop. The activePointer is not set on a touch device until you actually touch it, so you're basically binding and checking the mouse pointer (which doesn't do anything on mobile) in your code.

Swap the code in your Scene 1 update loop so it says: this.input.activePointer.isDown and it'll start doing as you expect. Once the scene has been touched, anyway.

Thanks for your help!

No worries - perhaps you could suggest somewhere I can add this in the docs to make it more obvious?

Hello photonstorm
I am using phaser3. I am developing a shooter game in mobile. I have set buttons for movement and a button for shooting. while the movement button is down and if i press shoot button its not working. but if i release movement button i can shoot. i played with activePointer and pointer1 and 2 with 2 active pointer in config. but its not working. please help.

Thank you for the wonderful framework, hope i can earn some day.. :-)

Hey Photonstorm

Got the solution. Just giving active pointers :2 in config doesnt do the trick(and in some article it says 2 is by default).
we need to add

this.input.addPointer(2) //or as 3 as needed

Lucky charm

Thank you

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Secretmapper picture Secretmapper  路  3Comments

SKEPDIMI picture SKEPDIMI  路  4Comments

rootasjey picture rootasjey  路  3Comments

JarLowrey picture JarLowrey  路  4Comments

maikthomas picture maikthomas  路  4Comments