it will be something like this. you need to tweak it for perfect movement and rotation.
[lua]local path = {}
local i =1;local j =1
local atan2 = math.atan2
local pi = math.pi
local function traceClicks(event)
if event.phase == “began” then
print(“reset”)
path ={}
i = 1
elseif event.phase == “moved” then
path[i] = {}
path[i].x = event.x
path[i].y = event.y
print(path[i].x)
i=i+1
end
end
Runtime:addEventListener(“touch”, traceClicks)
–create a circle ball
local ball = display.newText(“B”, 150, 150, nil,40 )
local animate
local posCount = 1
local prevx = 0
local prevy = 0
–moving the object – this is where animation takes place
local function moveObject(event)
if posCount <= #path then
if prevx == 0 then prevx = path[posCount].x ; prevy = path[posCount].y end
local deltax = path[posCount].x - prevx
local deltay = path[posCount].y - prevy
ball.rotation = atan2(deltay,deltax) * 180.0 / pi
ball.x = path[posCount].x
ball.y = path[posCount].y
prevx = path[posCount].x
prevy = path[posCount].y
posCount = posCount + 1
else
timer.cancel(animate)
end
end
– to move ball when we click the animate text
local function move()
posCount = 1
animate = timer.performWithDelay( 10, moveObject, #path )
return true
end
–create a text which when clicked will animate the object
local text = display.newText( “Animate!”, 220, 50, nil, 40 )
text:addEventListener(“touch”, move)[/lua] [import]uid: 71210 topic_id: 15108 reply_id: 56111[/import]