Getting 360 degrees rotation of a button when using transition.to

So essentially want to have a button rotate to 180 degrees, then stop. Then after user supplies the stimulus, the button continues going clockwise to the 360 degree mark, rinse and repeat. BUT I would like the button to only spin clockwise. Currently I had it as 180, 360, 180 but this last step makes it rotate counter-clockwise (b/c it’s traveling to the 180 degree mark and not the 540 degree mark). So next logical step is to make it add 180 degrees to it’s current rotational orientation, only problem is that I don’t know how to pull the rotational value from the transition.to statement. Perhaps there is even an easier method to dictate that I only want clockwise rotation? That would be obviously preferred. Here’s what I was working with before I ran into an error saying, “attempt to index field ‘to’ (a function value)”

Thanks!

[lua]

local rotationalAngle = 0

local function rotateFunction()

transition.to( upInfoArrow, {time = 1500, rotation = rotationalAngle + 180} )  – rotating the up arrow into down arrow

rotationalAngle = transition.to.rotation  – ** error is here

end

[/lua]

local vertices = { 0,-110, 27,-35, 105,-35, 65,90, 0,45, -65,90, -43,15, -105,-35, -27,-35, } local obj = display.newPolygon( display.contentCenterX, display.contentCenterY, vertices ) obj.rotation = 5 local firstRotation = obj.rotation transition.to( obj, {time = 1000, rotation= obj.rotation-180, onComplete = function ( ) local secondRotation = obj.rotation local changeRotation = secondRotation-firstRotation print(firstRotation, secondRotation, changeRotation) if (changeRotation \> 0) then -- postive print( "postive" ) elseif (changeRotation \< 0) then -- negative print( "negative" ) else print( "no change" ) end end} )

rotationalAngle = transition.to.rotation is not an api(that i am aware of)

Transitions support delta values where you could just transition and additional 180 degrees.

transition.to( object, { time = 500, delta = true, rotation = 180 } )

Then if you don’t want the rotation value to grow to large numbers you could do

transition.to( object, { time = 500, delta = true, rotation = 180, onComplete = function( target) target.rotation = target.rotation % 360; print( target.rotation); end } )

Rob

Thanks guys! I ended up using the transition.to method. Works great!

local vertices = { 0,-110, 27,-35, 105,-35, 65,90, 0,45, -65,90, -43,15, -105,-35, -27,-35, } local obj = display.newPolygon( display.contentCenterX, display.contentCenterY, vertices ) obj.rotation = 5 local firstRotation = obj.rotation transition.to( obj, {time = 1000, rotation= obj.rotation-180, onComplete = function ( ) local secondRotation = obj.rotation local changeRotation = secondRotation-firstRotation print(firstRotation, secondRotation, changeRotation) if (changeRotation \> 0) then -- postive print( "postive" ) elseif (changeRotation \< 0) then -- negative print( "negative" ) else print( "no change" ) end end} )

rotationalAngle = transition.to.rotation is not an api(that i am aware of)

Transitions support delta values where you could just transition and additional 180 degrees.

transition.to( object, { time = 500, delta = true, rotation = 180 } )

Then if you don’t want the rotation value to grow to large numbers you could do

transition.to( object, { time = 500, delta = true, rotation = 180, onComplete = function( target) target.rotation = target.rotation % 360; print( target.rotation); end } )

Rob

Thanks guys! I ended up using the transition.to method. Works great!