Yes, the “touch” is the one I’m using. My problem is that I have a moving camera, and the object doesn’t follow well the finger.
If the finger touches the screen and stays there without moving, I have found a way to correct the joint, calculating how much the game has scrolled in the meanwhile and calling again the drag function (with a “fake” parameter to distinguish from real touches).
But apparently there is no way to check if the finger moves slightly and then stays there: in this case the object stays behind the touch (imagine the camera moving from left to right).
I modified the original touch drag function to check if the object is moving or not, here is part of the code (I deleted the “params” stuff which is identical to the original)
[lua]local function dragFooter( event, params, fake )
local phase = event.phase
local stage = display.getCurrentStage()
local x = event.x - game.x
local y = event.y - game.y
print (phase)
if “began” == phase then
if nil == body then
body = display.newCircle( x, y, 20)
if (visibleFoot) then
body:setFillColor( 255, 255, 255, 100 )
else
body:setFillColor( 255, 255, 255, 1 )
en
body.isBullet = true
game:insert(body)
physics.addBody( body, “dynamic”, { density=0.3, friction=0.6, bounce = 0.5, radius=20, filter=footCollisionFilter } )
body.isNotMoving = true
end
body.tempJoint = physics.newJoint( “touch”, body, body.x, body.y )
elseif “moved” == phase then
if (not fake) then
body.isNotMoving = false
end
body.tempJoint:setTarget( x, y )
elseif “ended” == phase or “cancelled” == phase then
body.isNotMoving = false
body.tempJoint:removeSelf()
body:removeSelf()
body = nil
end
– Stop further propagation of touch event
return true
end
local function drag( event )
dragFooter( event, { maxForce=20000, frequency=4000, dampingRatio=1.0} , false)
end
– Camera follows ball automatically
local function moveCamera()
if (ball.x > 200 and ball.x < 10000) then
local oldx = game.x
game.x = -ball.x + 200
if (nil ~= body and body.isNotMoving) then
local diff = (game.x - oldx)
local event = {phase=“moved”, x=body.x+oldx, y=body.y}
local params = { maxForce=20000, frequency=4000, dampingRatio=1.0}
dragFooter(event,params,true)
end
end
end[/lua] [import]uid: 10482 topic_id: 3818 reply_id: 12921[/import]