Drag object : How to detect when the object doesn't move?

Hi :slight_smile:
I develop a game.
In that game, You can move the hero by dragging him.
When you drag him with movement, you can detect the movement with
the famous “moved” event.phase. You can then apply effect if necessary.
Ok. But how can I do to detect when the hero stop moving but he’s still dragging?
I didn’t find any event which can help me to apply effect when the hero “is waiting” for the next movement with the user finger still on screen…
Any idea?
Thanks for your help :slight_smile:
Olivier [import]uid: 160159 topic_id: 34326 reply_id: 334326[/import]

Well, there isn’t a phase for it. I would probably go with a timer.performWithDelay that is done on a move event. So let’s say we want the wait effect to occur after 1 second of idleness…
[lua]local waitTimer

local function waitTimerListener(event)

–do my wait effect here

end

local function onHeroTouch(event)

if event.phase == “moved” then

timer.cancel(waitTimer)
timer.performWithDelay( 1000, waitTimer)

end
end[/lua]
Something like that would be one way to do it. As a warning I typed that directly into the forum so there might be a typo or two.
[import]uid: 147305 topic_id: 34326 reply_id: 136450[/import]

Thank you very much for your answer budershank !
Let me precise my problem cause maybe I was not very clear on my first post.
In your example, you call waitTimerListener after a delay, but this call is not connected with a user action. it’s connected with a delay which has no connexion with what the user do on screen with his finger.
what I 'd like to do is to call the waitTimerListener when the user stop moving his finger on the screen (and so stop the hero moving too)) without removing his finger from the screen (the hero is still on a “drag mode”)
Thanks for your help :slight_smile:
Olivier [import]uid: 160159 topic_id: 34326 reply_id: 136453[/import]

The waitTimerListener is tied to the user moving his finger(or lack there of)… It then waits 1 second to see if another move event was fired. If it was the timer resets. If not, then waitTimerListener is fired.

You only have a began, moved and ended event. There is no ‘not moved’ event. That being the case any solution you find will simply be method that achieves essentially the same thing which is detecting when there is a lapse between moved events(or I guess moved and ended which was not in my code example). [import]uid: 147305 topic_id: 34326 reply_id: 136454[/import]

I understand !
Thank you so much!
Olivier [import]uid: 160159 topic_id: 34326 reply_id: 136455[/import]

Well, there isn’t a phase for it. I would probably go with a timer.performWithDelay that is done on a move event. So let’s say we want the wait effect to occur after 1 second of idleness…
[lua]local waitTimer

local function waitTimerListener(event)

–do my wait effect here

end

local function onHeroTouch(event)

if event.phase == “moved” then

timer.cancel(waitTimer)
timer.performWithDelay( 1000, waitTimer)

end
end[/lua]
Something like that would be one way to do it. As a warning I typed that directly into the forum so there might be a typo or two.
[import]uid: 147305 topic_id: 34326 reply_id: 136450[/import]

Thank you very much for your answer budershank !
Let me precise my problem cause maybe I was not very clear on my first post.
In your example, you call waitTimerListener after a delay, but this call is not connected with a user action. it’s connected with a delay which has no connexion with what the user do on screen with his finger.
what I 'd like to do is to call the waitTimerListener when the user stop moving his finger on the screen (and so stop the hero moving too)) without removing his finger from the screen (the hero is still on a “drag mode”)
Thanks for your help :slight_smile:
Olivier [import]uid: 160159 topic_id: 34326 reply_id: 136453[/import]

The waitTimerListener is tied to the user moving his finger(or lack there of)… It then waits 1 second to see if another move event was fired. If it was the timer resets. If not, then waitTimerListener is fired.

You only have a began, moved and ended event. There is no ‘not moved’ event. That being the case any solution you find will simply be method that achieves essentially the same thing which is detecting when there is a lapse between moved events(or I guess moved and ended which was not in my code example). [import]uid: 147305 topic_id: 34326 reply_id: 136454[/import]

I understand !
Thank you so much!
Olivier [import]uid: 160159 topic_id: 34326 reply_id: 136455[/import]