It doesn’t look like you are using physics and I think that collision code is used with physics engine. I never use the physics engine so I cannot be sure, but here is one way to do it, not using physics. (using your code with a few changes)
local composer = require ( "composer" ) local physics = require("physics") local objTrans physics.start() local function point\_in\_rect( pointX, pointY, img ) local left = img.x - (img.width \* .5) local top = img.y - (img.height \* .5) if pointX \>= left and pointX \<= left + img.width and pointY \>= top and pointY \<= top + img.height then return true else return false end end local square = display.newRect(display.contentCenterX,126,55,50) square:setFillColor(1,0,0) local rectangle = display.newRect(17,270,39,141) rectangle:setFillColor(0,0,1) local shade = display.newRect(display.contentCenterX,rectangle.y,display.actualContentWidth-60,rectangle.height) shade:setFillColor( 0.196078, 0.803922, 0.196078) local function listener1( obj ) print( "Transition 1 completed on object: " .. tostring( obj ) ) end objTrans = transition.to( square, {x=display.contentCenterX, y=display.contentCenterY}) --, onComplete=listener1 } ) local function gameLoop() if point\_in\_rect(square.x, square.y, shade) then print("Colliding") -- MUST END (REMOVE) THE GAMELOOP EVENT LISTENER transition.cancel(objTrans) Runtime:removeEventListener("enterFrame", gameLoop) composer.gotoScene("scene1") end end Runtime:addEventListener("enterFrame", gameLoop)
Hope it is helpful
Bob