Greetings everyone,
I’m trying to throw an object along the swipe direction and I found that MultiPuck example does it really well, except the object dragging part. I don’t want to drag the object, I want to make it work with Runtime touch listener and swipe throw the object to that direction without making the object move to the tap location.
How can I do it with or without MultiPuck example?
Here is the code for MultiPuck example:
function dragBody( event, params ) local body = event.target local phase = event.phase local stage = display.getCurrentStage() if "began" == phase then stage:setFocus( body, event.id ) body.isFocus = true -- Create a temporary touch joint and store it in the object for later reference if params and params.center then -- drag the body from its center point body.tempJoint = physics.newJoint( "touch", body, body.x, body.y ) else -- drag the body from the point where it was touched body.tempJoint = physics.newJoint( "touch", body, event.x, event.y ) end -- Apply optional joint parameters if params then local maxForce, frequency, dampingRatio if params.maxForce then -- Internal default is (1000 \* mass), so set this fairly high if setting manually body.tempJoint.maxForce = params.maxForce end if params.frequency then -- This is the response speed of the elastic joint: higher numbers = less lag/bounce body.tempJoint.frequency = params.frequency end if params.dampingRatio then -- Possible values: 0 (no damping) to 1.0 (critical damping) body.tempJoint.dampingRatio = params.dampingRatio end end elseif body.isFocus then if "moved" == phase then -- Update the joint to track the touch body.tempJoint:setTarget( event.x, event.y ) elseif "ended" == phase or "cancelled" == phase then stage:setFocus( body, nil ) body.isFocus = false -- Remove the joint when the touch ends body.tempJoint:removeSelf() end end -- Stop further propagation of touch event return true end