Hi
Is it possible to throw or fling an object with a swipe while preventing the object from being dragged?
I don’t want the user to be able to drag the ball to the target by continuing the swipe. The swipe is to initiate the throw and set it’s direction. Velocity will be a constant.
The multipuck sample allows the pucks to be dragged.
The answer in the following post does the throw/fling but the object can still be dragged.
https://forums.coronalabs.com/topic/57339-swipe-to-throw-object-without-dragging/
This is the code from that post:
[lua]
centerX = display.contentCenterX
centerY = display.contentCenterY
screenTop = math.floor(display.screenOriginY)
screenLeft = math.floor(display.screenOriginX)
screenBottom = display.contentHeight - screenTop
screenRight = display.contentWidth - screenLeft
screenWidth = screenRight - screenLeft
screenHeight = screenBottom - screenTop
local physics = require(“physics”)
physics.start()
local leftWall = display.newRect(screenLeft - 10, centerY, 20, screenHeight)
local rightWall = display.newRect(screenRight + 10, centerY, 20, screenHeight)
local topWall = display.newRect(centerX, screenTop - 10, screenWidth, 20)
local bottomWall = display.newRect(centerX, screenBottom + 10, screenWidth, 20)
physics.addBody(leftWall, “static”)
physics.addBody(rightWall, “static”)
physics.addBody(topWall, “static”)
physics.addBody(bottomWall, “static”)
local square = display.newRect(centerX, centerY, screenWidth*.075, screenWidth*.075)
physics.addBody(square)
square.gravityScale = 0
local tempBody
local function touchListener(event)
local phase=event.phase
if phase == “began” then
tempBody = display.newCircle(event.x, event.y, 30)
tempBody.isVisible=false
physics.addBody(tempBody)
tempBody.isSensor = true
tempBody.joint = physics.newJoint(“touch”, tempBody, event.x, event.y)
function tempBody.enterFrame(event)
local vx, vy = tempBody:getLinearVelocity()
square:setLinearVelocity(vx, vy)
square.angularVelocity = tempBody.angularVelocity
end
Runtime:addEventListener(“enterFrame”, tempBody)
elseif phase == “moved” then
tempBody.joint:setTarget(event.x, event.y)
elseif phase == “cancelled” or phase == “ended” then
Runtime:removeEventListener(“enterFrame”, tempBody)
tempBody.joint:removeSelf()
display.remove(tempBody)
end
end
Runtime:addEventListener(“touch”, touchListener)
[/lua]
Thanks