Reputation: 9368
I'm trying to make a simple game that has a single input based on lessmilk.com's Flappy Bird tutorial. On the keyboard you hit space to jump, but on touch enabled devices I'd like to just have the users touch anywhere on the canvas to jump.
Looking at the input docs it seems straight forward to capture touch input for a sprite, but I'd like the user to be able click/touch anywhere.
What's the "Phaser way" to capture all touch events? Do I need to do something hacky like create an invisible sprite covering the entire canvas? Should I bypass the phaser and just attach DOM event handlers?
Upvotes: 1
Views: 4604
Reputation: 9368
Seems like I'd been misunderstanding the role of phaser's input manager. I'd been trying to use game.input.touch
to hook those events but I just needed to be using the higher level input.onDown
event:
// click / touch to jump
game.input.onDown.add(this.jump, this);
Upvotes: 6