Better way to rotate?

Hi all,
I’m brand new to Corona… just started digging in to it today.

I’m playing around with some stuff and just wanted to see if I could get some simple Hello World text to rotate endlessly.

I’ve sort of gotten it to work with the code below, I say sort of as it does keep rotating, but there’s a very short pause at the start of each cycle.

I’m sure there’s a better way to do this, so if you have any tips that’d be great.
Thanks.

Here’s the code I’m using:

[code]
local rotate
local trans
local rotvalue = 0
local textObject = display.newText( “Hello World!”, 50, 50, nil, 24 )
textObject:setTextColor( 255,255,255 )

function rotate(e)
rotvalue = rotvalue -360
trans = transition.to(textObject,{rotation = rotvalue, time=1000, onComplete=rotate})
end

rotate()
[/code] [import]uid: 209495 topic_id: 34571 reply_id: 334571[/import]

How about this minor variation, it has far less jitter overall:

[code]
local rotate
local trans
local rotvalue = 0
local textObject = display.newText( “Hello World!”, 50, 50, nil, 24 )
textObject:setTextColor( 255,255,255 )

function rotate(e)
rotvalue = rotvalue -360000
trans = transition.to(textObject,{rotation = rotvalue, time=1000000, onComplete=rotate})
end

rotate()
[/code] [import]uid: 79933 topic_id: 34571 reply_id: 137463[/import]

This is the downside of transitions; the initialization time is just enough that you can’t pull it off in a single frame.

An alternative way would be to use Runtime.

[code]function rotate(e)
rotvalue = rotvalue - 2
textObject.rotation = rotvalue
end

Runtime:addEventListener(“enterFrame”, rotate)[/code]

Runtime allows you to apply very powerful (and dangerous if you overuse) effects, in this case on every frame! You can’t pull off a transition in that time so you’re setting the per frame rotation here. A smaller number means smoother, while a higher number means faster.

Runtime events have to be stopped manually (:removeEventListener) but are perfect for when you need priority events or seamless actions. [import]uid: 41884 topic_id: 34571 reply_id: 137464[/import]

Thanks so much, this is great info! [import]uid: 209495 topic_id: 34571 reply_id: 137728[/import]

How about this minor variation, it has far less jitter overall:

[code]
local rotate
local trans
local rotvalue = 0
local textObject = display.newText( “Hello World!”, 50, 50, nil, 24 )
textObject:setTextColor( 255,255,255 )

function rotate(e)
rotvalue = rotvalue -360000
trans = transition.to(textObject,{rotation = rotvalue, time=1000000, onComplete=rotate})
end

rotate()
[/code] [import]uid: 79933 topic_id: 34571 reply_id: 137463[/import]

This is the downside of transitions; the initialization time is just enough that you can’t pull it off in a single frame.

An alternative way would be to use Runtime.

[code]function rotate(e)
rotvalue = rotvalue - 2
textObject.rotation = rotvalue
end

Runtime:addEventListener(“enterFrame”, rotate)[/code]

Runtime allows you to apply very powerful (and dangerous if you overuse) effects, in this case on every frame! You can’t pull off a transition in that time so you’re setting the per frame rotation here. A smaller number means smoother, while a higher number means faster.

Runtime events have to be stopped manually (:removeEventListener) but are perfect for when you need priority events or seamless actions. [import]uid: 41884 topic_id: 34571 reply_id: 137464[/import]

Thanks so much, this is great info! [import]uid: 209495 topic_id: 34571 reply_id: 137728[/import]