Continual Rotation

Hi! I have an object that I want to begin rotating with the press of a button and not stop until another button is pressed. Below is what I have so far. It just does a quick rotation then stops.

local turnon = function (event )
if event.phase == “release” then
blades.rotation = blades.rotation + 32
end
end

local onbutton = widget.newButton{
default = “buttonoff.png”,
defaultX = 370,
defaultY = 66,
onRelease = turnon
}

onbutton.x = display.contentHeight / 3
onbutton.y = display.contentWidth / .716 --397
Also, how do you put the code in a little “window” thing? Thanks [import]uid: 39302 topic_id: 23436 reply_id: 323436[/import]

I suggest you watch the Ansca gear rotation tutorial, search the videos, or should be this link.

http://www.youtube.com/watch?feature=player_embedded&v=YVRRotMYXyI#!

To list as code use the code tags before and after the code.
< code >
[import]uid: 107098 topic_id: 23436 reply_id: 93912[/import]

I watched the vid, and I have this now…

< code >
local animate = function (event )
if event.phase == “release” then
blades.rotation = blades.rotation + 32
end
end

local onbutton = widget.newButton{
default = “buttonoff.png”,
defaultX = 370,
defaultY = 66,
onRelease = Runtime:addEventListener( “enterFrame”, animate )
}
< code >

When I reload the simulator though, it begins rotating immediately. [import]uid: 39302 topic_id: 23436 reply_id: 94108[/import]

Ok try something like the following:

  
 local rotationAmount = 0  
  
 local animate = function (event )  
 blades.rotation = blades.rotation + rotationAmount  
 end  
   
 local buttonOnPressed{  
 if event.phase == "release" then  
 rotationAmount = 32  
 end  
}  
  
local onbutton = widget.newButton{  
 default = "buttonoff.png",  
 defaultX = 370,  
 defaultY = 66,  
 onRelease = buttonOnPressed  
 }  
  
Runtime:addEventListener( "enterFrame", animate )  
  

Then to stop the animation either add another button that sets the rotationAmount value to 0 or remove the EventListener.

Its worth watching all the gear animation videos I think there is at least 5.

RE: < code > Don’t use spaces between the < and > the word code. I just did that because the text wouldn’t show up otherwise.
[import]uid: 107098 topic_id: 23436 reply_id: 94120[/import]

Thank you! I’ll check out the other vids.

Nathan
[import]uid: 39302 topic_id: 23436 reply_id: 94122[/import]