Jump to content

Trying to distinguish between input up and drag


Recommended Posts

Hello all.  I just started using Phaser and I really love it.  I am however struggling with some basic functionality.


I have a use case where I'm trying to have a sprite behave differently depending on whether it is being dragged, or if just clicked.  I would like to allow the sprite to be dragged, but rotate the sprite 90 deg if only clicked.  So far I have not been able to distinguish if only a click has occured.


I have been trying to use the sprite.input.isDragged property.  Unfortunately it seems to report 'true' as soon as the mouse is pressed, and not waiting for any drag event.  


here is a jsfiddle to demonstrate...




Is there another way I can solve this problem?






Link to comment
Share on other sites

In this case, a click would be releasing the mouse or finger from the sprite. If you align to that, you have no issue. A mousedown could then be intepreted as a click.


Keep track of movement to be able to distunguish from drag and click.

Link to comment
Share on other sites

I have the same problem as the questioner did, and I am wondering this too.


Furthermore, I also need the startDrag and stopDrag events.


The solution that came to mind is :


1. set onInputDown events which gives click marker (boolean) set to TRUE.

2. set onInputUp events which activate the click method if click marker is TRUE.

3. set onStartDrag events which gives certain delay in ms (expected delay to click) and then set marker to FALSE.


Is this a good approach/solution for this?



Link to comment
Share on other sites

Thank you for the responses.  What I did was trap events :


sprite.events.onDragStart.add(startDrag, this);
sprite.events.onDragStop.add(stopDrag, this);
...and check to see if the sprite moved.  If not I processed it as a simple click.  
However I would like to suggest that the property .isDragged should not be set to true unless the sprite does infact get dragged... even a little.
Thanks... really loving Phaser!
Link to comment
Share on other sites


  • Recently Browsing   0 members

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