I want to touch an object and rotate it clockwise or anticlockwise based on the touch’s x&y:
function rotatePlayer(event) local obj = event.target if (event.phase == "began") then display.getCurrentStage():setFocus( obj ) obj.startX = (event.x - obj.x) obj.startY = (event.y - obj.y) obj.startAngle = math.atan2( obj.startY, obj.startX ) \* (180 / math.pi) elseif (event.phase == "moved") then local dX = (event.x - obj.x) local dY = (event.y - obj.y) local angle = math.atan2( dY, dX ) \* (180 / math.pi) local dAngle = (angle - obj.startAngle) obj.rotation = dAngle elseif (event.phase == "ended") then end end
The result is not as expected, some jerky movement and not consistent with the touch’s gesture. Any help would be appreciated.