Using Runtime:addEventListener for a fixed period of time

Hi,

I have used math.sin and math.cos functions to start a bird moving in a circle at runtime. however, i want the bird to stop after, say 3 revolutions… or if that’s not possible, i want it to stop after, say 5 seconds.

How can i do that? [import]uid: 175611 topic_id: 30782 reply_id: 330782[/import]

Hello,
This should be simple. On whatever condition you desire, 3 revolutions, 5 seconds, etc., just call a function that stops the Runtime listener…

Runtime:removeEventListener( ... ) --inside parens use the same function name that runs while it's active  

That should do exactly what you need!
Brent [import]uid: 9747 topic_id: 30782 reply_id: 123231[/import]

thanks, but how do i set the time for this? i’m a newbie, so sorry for questions about such basics.

what i want to do is :

if (time since start of motion is 5 seconds) then
Runtime:removeEventListener()

should i use event.time? [import]uid: 175611 topic_id: 30782 reply_id: 123233[/import]

This should help : http://docs.coronalabs.com/api/library/timer/performWithDelay.html [import]uid: 87794 topic_id: 30782 reply_id: 123248[/import]

That worked. thank you [import]uid: 175611 topic_id: 30782 reply_id: 123377[/import]

Hello,
This should be simple. On whatever condition you desire, 3 revolutions, 5 seconds, etc., just call a function that stops the Runtime listener…

Runtime:removeEventListener( ... ) --inside parens use the same function name that runs while it's active  

That should do exactly what you need!
Brent [import]uid: 9747 topic_id: 30782 reply_id: 123231[/import]

thanks, but how do i set the time for this? i’m a newbie, so sorry for questions about such basics.

what i want to do is :

if (time since start of motion is 5 seconds) then
Runtime:removeEventListener()

should i use event.time? [import]uid: 175611 topic_id: 30782 reply_id: 123233[/import]

This should help : http://docs.coronalabs.com/api/library/timer/performWithDelay.html [import]uid: 87794 topic_id: 30782 reply_id: 123248[/import]

That worked. thank you [import]uid: 175611 topic_id: 30782 reply_id: 123377[/import]