On repeated transition object doesn't react on touch/collision

Hi,

I Have ball as as a dynamic body who is falling from the screen top on repeated transition and it supposed to react with a swipe function. And it’s react but just for the first time, on the second fall it doesn’t recognise swipe and don’t interact with other static bodies.

function ballFall() ball = display.newImage("images/ball.png", centerX, screenTop) physics.addBody(ball, "dynamic") ball.gravityScale = 0 ball.type = "ball" local function removeBall(obj) obj:removeSelf() transition.to(ball, {time2000, y=screenBottom, x=centerX, onComplete=ballFall}) end transition.to(ball, {time=2000, y=screenBottom, x=centerX, onComplete=removeBall}) end ballFall() local function swipe(event) local phase=event.phase if phase == "began" then ball:setLinearVelocity(0,0) elseif phase == "moved" then transition.cancel(action) elseif phase == "cancelled" or phase == "ended" then local eventXMove = (event.xStart - event.x)\*-3 local eventYMove = (event.yStart - event.y)\*-3 ball:setLinearVelocity(eventXMove, eventYMove) end end ball:addEventListener("touch", swipe)

I want to help you but are you sure this is the code you are using for your ball?

Yes, I slightly modified code, so it can work now properly just pasted in. Also added walls for collision function witch shows same behavior as touch.
You can see that is possible to play with the swipe function on the ball if you catch it on the first transition, but it’s not possible on the next transitions.

centerX = display.contentCenterX centerY = display.contentCenterY screenLeft = display.screenOriginX screenWidth = display.contentWidth - screenLeft \* 2 screenRight = screenLeft + screenWidth screenTop = display.screenOriginY screenHeight = display.contentHeight - screenTop \* 2 screenBottom = screenTop + screenHeight display.contentWidth = screenWidth display.contentHeight = screenHeight local physics = require("physics") physics.start() local leftWall = display.newRect(screenLeft+1, centerY, 10, screenHeight) local topWall = display.newRect(centerX, screenTop+1, screenWidth, 10) local rightWall = display.newRect(screenRight-1, centerY, 10, screenHeight) local bottomWall = display.newRect(centerX, screenBottom-1, screenWidth, 10) leftWall.type = "wall" topWall.type = "wall" rightWall.type = "wall" bottomWall.type = "wall" physics.addBody(leftWall, "static") physics.addBody(rightWall, "static") physics.addBody(topWall, "static") physics.addBody(bottomWall, "static") local ball function ballFall() ball = display.newCircle(150, 20, 80) physics.addBody(ball, "dynamic") ball.gravityScale = 0 ball.type = "ball" local function removeBall(obj) obj:removeSelf() transition.to(ball, {time2000, y=screenBottom, x=150, onComplete=ballFall}) end transition.to(ball, {time=2000, y=screenBottom, x=150, onComplete=removeBall}) end ballFall() local function swipe(event) local phase=event.phase if phase == "began" then ball:setLinearVelocity(0,0) elseif phase == "moved" then elseif phase == "cancelled" or phase == "ended" then transition.cancel(action) local eventXMove = (event.xStart - event.x)\*-3 local eventYMove = (event.yStart - event.y)\*-3 ball:setLinearVelocity(eventXMove, eventYMove) end end ball:addEventListener("touch", swipe) local function ballCollision(self, event) if event.phase == "began" then if event.target.type == "ball" and event.other.type == "wall" then print("yes") end end end ball.collision = ballCollision ball:addEventListener("collision", ball)

I want to help you but are you sure this is the code you are using for your ball?

Yes, I slightly modified code, so it can work now properly just pasted in. Also added walls for collision function witch shows same behavior as touch.
You can see that is possible to play with the swipe function on the ball if you catch it on the first transition, but it’s not possible on the next transitions.

centerX = display.contentCenterX centerY = display.contentCenterY screenLeft = display.screenOriginX screenWidth = display.contentWidth - screenLeft \* 2 screenRight = screenLeft + screenWidth screenTop = display.screenOriginY screenHeight = display.contentHeight - screenTop \* 2 screenBottom = screenTop + screenHeight display.contentWidth = screenWidth display.contentHeight = screenHeight local physics = require("physics") physics.start() local leftWall = display.newRect(screenLeft+1, centerY, 10, screenHeight) local topWall = display.newRect(centerX, screenTop+1, screenWidth, 10) local rightWall = display.newRect(screenRight-1, centerY, 10, screenHeight) local bottomWall = display.newRect(centerX, screenBottom-1, screenWidth, 10) leftWall.type = "wall" topWall.type = "wall" rightWall.type = "wall" bottomWall.type = "wall" physics.addBody(leftWall, "static") physics.addBody(rightWall, "static") physics.addBody(topWall, "static") physics.addBody(bottomWall, "static") local ball function ballFall() ball = display.newCircle(150, 20, 80) physics.addBody(ball, "dynamic") ball.gravityScale = 0 ball.type = "ball" local function removeBall(obj) obj:removeSelf() transition.to(ball, {time2000, y=screenBottom, x=150, onComplete=ballFall}) end transition.to(ball, {time=2000, y=screenBottom, x=150, onComplete=removeBall}) end ballFall() local function swipe(event) local phase=event.phase if phase == "began" then ball:setLinearVelocity(0,0) elseif phase == "moved" then elseif phase == "cancelled" or phase == "ended" then transition.cancel(action) local eventXMove = (event.xStart - event.x)\*-3 local eventYMove = (event.yStart - event.y)\*-3 ball:setLinearVelocity(eventXMove, eventYMove) end end ball:addEventListener("touch", swipe) local function ballCollision(self, event) if event.phase == "began" then if event.target.type == "ball" and event.other.type == "wall" then print("yes") end end end ball.collision = ballCollision ball:addEventListener("collision", ball)