Try this…
[lua]local physics = require(“physics”)
physics.start()
local ball = display.newImage( “images/ball.png” )
ball.x = 40; ball.y = 280
physics.addBody( ball, “kinematic”, { friction=0.7 } )
local function startDrag( event )
local phase = event.phase
if “began” == phase then
– Store initial position
x0 = event.x
y0 = event.y
ballx0 = ball.x
bally0 = ball.y
print(x0, y0)
– Stop current motion, if any
ball:setLinearVelocity( 0, 0 )
ball.angularVelocity = 0
elseif “moved” == phase or “ended” == phase or “cancelled” == phase then
ball.x = ballx0 + event.x - x0
ball.y = bally0 + event.y - y0
end
– Stop further propagation of touch event!
return true
end
Runtime:addEventListener( “touch”, startDrag )[/lua]
[import]uid: 48521 topic_id: 10147 reply_id: 37132[/import]