Hello There!
I want to rotate an object only in clockwise direction not in anti clockwise direction and it should stop after few complete rotations.
Here is my code:
local circle = display.newImageRect( "stearing.png", 158, 158 ) circle.x = display.contentWidth / 2 circle.y = display.contentHeight / 2 local function rotateObj(event) local t = event.target local phase = event.phase if (phase == "began") then display.getCurrentStage():setFocus( t ) t.isFocus = true t.x1 = event.x t.y1 = event.y elseif t.isFocus then if (phase == "moved") then t.x2 = event.x t.y2 = event.y angle1 = 180/math.pi \* math.atan2(t.y1 - t.y , t.x1 - t.x) angle2 = 180/math.pi \* math.atan2(t.y2 - t.y , t.x2 - t.x) rotationAmt = angle1 - angle2 t.rotation = t.rotation - rotationAmt t.x1 = t.x2 t.y1 = t.y2 elseif (phase == "ended") then display.getCurrentStage():setFocus( nil ) t.isFocus = false end end return true end circle:addEventListener("touch", rotateObj)
Above code works for both the directions i.e. clockwise and anti clockwise.
So, I want to know what changes I have to make to achieve the desired task.
Any help would be highly appreciated.
Thanks,