Stopping an "animate" event

Hello! I have this code gong on…

local function animate( event )
blades.rotation = blades.rotation + 33
end

I’m wondering how I can stop it. And I don’t mean delete the code… I want to stop it with the press of a button. I know how to make the button and stuff, but I’m looking for a little command that will pause/stop it. Thank You!

Nathan [import]uid: 39302 topic_id: 16876 reply_id: 316876[/import]

How are you doing this? On a Runtime event listener or a timer, or what?

Can’t really say anything without knowing how it is actually working :wink: [import]uid: 52491 topic_id: 16876 reply_id: 63223[/import]

Okay. I’m using a runtime event listener. “Runtime:addEventListener( “enterFrame”, animate )”

I’ve been using your tutorials and they are very handy!! thank you!

Nathan [import]uid: 39302 topic_id: 16876 reply_id: 63233[/import]

Glad to hear it :slight_smile: Thanks.

To stop the event, do this;
[lua]Runtime:removeEventListener( “enterFrame”, animate )[/lua]

You could put that in a function by itself and tie it to a button.

Make sense? :slight_smile:

Peach [import]uid: 52491 topic_id: 16876 reply_id: 63251[/import]

Thank you so much! :slight_smile: [import]uid: 39302 topic_id: 16876 reply_id: 63255[/import]

I have another question… I hope I’m not bothering you.
Is there any way to make the rotations speed up to +33 gradually?

Nathan [import]uid: 39302 topic_id: 16876 reply_id: 63279[/import]

Hey there,

No, not bothering me at all :slight_smile: (Sorry for the delay, was traveling back to Australia and am only now back online.)

You want it to go up gradually?

Try this in a new project as an example;
[lua]local background = display.newImage( “world.jpg” )

local blades = display.newRect( 140, 140, 40, 40 )

local myRotation = 1

local function spin ()
blades.rotation = blades.rotation + myRotation
myRotation = myRotation+1
end
Runtime:addEventListener(“enterFrame”, spin)[/lua]

That will look a little odd as the rotation keeps on going up, you’d want to limit it.

Make sense?

Peach :slight_smile: [import]uid: 52491 topic_id: 16876 reply_id: 63712[/import]