Spin a sprite

I want to spin a sprite , I tried the following but it does not seem to do what I expect.

local function rotatehead()
for i = 0, 360, 15 do
instanceHead:rotate(i)
end
end

Any help is greatly appreciated.
[import]uid: 28709 topic_id: 14931 reply_id: 314931[/import]

you need to understand how the iOS renderer works, you will see the last position.

you need to call the roatation in small increments, it does not work like other *windows* based programming languages, unfortunately…

local angle = 0  
local step =15  
local speed = 100  
local rotate  
  
local instanceHead = display.newRect(10,100,200,50)  
 instanceHead:setFillColor(255,0,0)  
  
function rotate()  
 instanceHead.rotation=angle  
 angle = angle+step  
  
 if angle\<=360 then  
 timer.performWithDelay(speed ,rotate)  
 end  
end  
  
timer.performWithDelay(1000,rotate) -- starts after 1 second  

Now you should be able to see the same being rotated, another thing to note is that you are using rotate, which uses a delta angle from the last position, where as .rotation is the abosulte angle.

So if you want to use :rotate, you can just keep passing it 15 (step) as that is the increment that you are after.

Just created an instanceHead for those that would want to try the code by copy/paste from here.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 14931 reply_id: 55155[/import]