Jump to content

Game.input.onDown question


Tácio Sousa
 Share

Recommended Posts

Hi people, i'm here again with new questions.

 

I started a Space Invaders project with Phaser, and I set the ship (player) for move when one sprite (with inputEnabled = true) dispatch his input event (button.events.onInputDown.add(move, this)). The player moves normal, but if you click the button and continues holding him OUT of the button, the player will continue moving forever, until you click one more time in same button to call the onInputUp function.

 

I can use the game.input.onUp to fix the release of button, but here comes the question : How i do for game.input.onDown return a Sprite if there's one clicked? I need something like "return the sprite at inputX and Y" on update function, for substitute the button events for game.input.onDown and make the buttons work like any other game.

 

If a cannot resolve this, the player will always have to click and release all buttons for move instead hold the finger and only move towards the right button, as we make in any virtual D-Pad.

Link to comment
Share on other sites

I make as you said Rich, I change the sprite.input.onDown for game.input.onDown and put the sprite.input.pointerOver() verification in each sprite, and now it works perfectly, but only in browser and without Enable touch events.

 

I upload the index for test, and run inside one iPad 4 (iOs 7.0.2) and other iPad 2 (iOs 6.1.3, here I have another problem, in this iPad the sprite colors have changed to something like "more clean", like 0x0000FF to 0x0000DD) and both iPads don't recognize the Phaser pointerOver method, so the player cannot move or shot.

 

Here's the example. You can see the code if you want. I don't know if i have to use or enabled any other thing to touch mobile works...

Link to comment
Share on other sites

buttonUp.input.pointerOver()

If you don't give it a pointer ID it will default to zero, which is probably not the ID of the finger that was pressed onto the canvas. Basically each finger has a unique ID, for example the finger using the d-pad might be ID1 while the finger on the fire button might be ID2 - basically you need to capture the ID when its pressed down on the d-pad and then use that in the pointerOver checks. I know it seems a bit strange, but it's actually quite flexible as it allows for multiple presses on a single Sprite.

Link to comment
Share on other sites

Right, but I have 2 questions here :

 

1 - How I do to give this pointer IDs to the sprites? And what's the pointer of all fingers?

 

2 - If I put another "capture" style function, i'll have the same problem that I have before (keep pressing down the button as I said).

 

Can you give me a light for this problem?

 

Sorry for boring you so many times Rich, i'm really noob in JS development and more in Phaser.

Link to comment
Share on other sites

  • 3 weeks later...

I know, am preparing an example for you (no ETA yet, sorry, but it will be part of the 1.0.7 update)

 

I've got a working tech demo integrating Austin Hallock's HTML5 virtual game controller (https://github.com/austinhallock/html5-virtual-game-controller) with Phaser 1.1 (dev branch).  It's currently written in coffeescript, but would you folks like me to share this here?  I'm planning to use it as part of a tutorial I'm putting together, but it may become irrelevant if you're introducing some other sort of virtual dpad support in Phaser.next...

Link to comment
Share on other sites

Hi guys, i'm here again.

 

I've try one more time with sprite.pointerOver problem, and still have the same result. I put "buttonUp".input.pointerOver.id = 1,2,3 and always get the same result, running in browser but no in iPad. (The default ID is 1)

 

This is the right way to set ID pointer?

Here's the url and the source : Site

 

Sorry for borring all this time along, i'm really VERY noob in JS development, much more in Phaser. =/

Link to comment
Share on other sites

  • 2 weeks later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...