I want to create a spinning wheel.
So far I managed to rotate the object, when user starts dragging the wheel. It is fixed at the center and always rotates to users touch. Now I have the problem - second time users starts dragging/spinning the wheel it jumps…
local spinner = display.newImage( "img/spin.png") spinner.x, spinner.y = display.contentCenterX, display.contentCenterY spinner:scale( .3, .3 ) local adjustment = 0 local PI = 3.14159265358 local function onTouch(e) if(e.phase == "began") then local dx = e.x - spinner.x local dy = e.y - spinner.y adjustment = math.atan2(dy,dx) \* 180 / PI end if(e.phase == "moved") then local dx = e.x - spinner.x local dy = e.y - spinner.y spinner.rotation = (math.atan2(dy,dx) \* 180 / PI) - adjustment end end Runtime:addEventListener('touch', onTouch)