smatthews1999 Posted September 21, 2014 Share Posted September 21, 2014 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... http://jsfiddle.net/smatthews1999/2uqp7yLp/ Is there another way I can solve this problem? Thanks, Sam Link to comment Share on other sites More sharing options...
Robske Posted September 22, 2014 Share Posted September 22, 2014 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 More sharing options...
hyude Posted September 22, 2014 Share Posted September 22, 2014 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? Thanks Link to comment Share on other sites More sharing options...
Robske Posted September 22, 2014 Share Posted September 22, 2014 hyude, sounds like a good plan Link to comment Share on other sites More sharing options...
smatthews1999 Posted September 26, 2014 Author Share Posted September 26, 2014 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 More sharing options...
Recommended Posts