basically i have a game where things are falling form the top of the screen and when it touches player or the bottom platform its supposed to disappear
it works until i throw it into a loop
im trying to spawn multiple of the grayDot object and i cant figure it out without a loop of some sort so i tried the timer.performWithDelay and it spawns multiple the exact way i want it except it wont register the collision between the 2 objects
but it is detecting collision because it is printing 1 and 2 which i added into the began and ended phase if statements
im just wanting to know how i could get the graydot to dissapear when it touches the player or the platform
and where it says ball in the code is the player
please help
display.setStatusBar( display.HiddenStatusBar ) local physics = require("physics") physics.start() physics.setGravity (0, 25) --Variable local gravity = .5 local background = display.newImageRect("background.png",320, 668 ) background.x = display.contentCenterX background.y = display.contentCenterY local platform = display.newImageRect("Platform.png", 350, 35) platform.x = display.contentCenterX platform.y = display.contentHeight - 2 platform.yScale = display.contentScaleY + 1 physics.addBody(platform, "static", {bounce = .2, friction = 1}) local ball = display.newImageRect("square.png", 50, 50) ball.x = display.contentCenterX ball.y = display.contentCenterY physics.addBody(ball, "dynamic", {bounce = 0, friction = 1}) local gravity = .5 local loop = 0 local numHits = 3 --Functions local function onTouch(event) local ball = event.target local phase = event.phase if ( "began" == phase ) then -- Set touch focus on the ball display.currentStage:setFocus( ball ) -- Store initial offset position ball.touchOffsetX = event.x - ball.x elseif ( "moved" == phase ) then -- Move the ball to the new touch position ball.x = event.x - ball.touchOffsetX if ball.x \< 20 then ball.x = 20 display.currentStage:setFocus(nil) elseif event.x \> 300 then ball.x = 300 display.currentStage:setFocus(nil) end elseif ( "ended" == phase or "cancelled" == phase ) then -- Release touch focus on the ball display.currentStage:setFocus( nil ) end return true end local function onCollision(event) local phase = event.phase if phase == "began" then local obj1 = event.object1 local obj2 = event.object2 if (obj1 == ball and obj2 == grayDot)or (obj1 == grayDot and obj2 == ball) then display.remove(obj2) numHits = numHits - 1 print(3) elseif (obj1 == platform and obj2 == grayDot)or (obj1 == grayDot and obj2 == platform) then display.remove(obj2) print(4) end print(1) elseif phase == "ended" then print(2) end return true end function spawn() grayDot = display.newImageRect("gray\_dot.png", 30, 30) grayDot.x = math.random(20, 300) grayDot.y = -60 physics.addBody(grayDot, "dynamic", {bounce = 0}) grayDot.gravityScale = gravity end -- format and display Runtime:addEventListener("collision", onCollision) ball:addEventListener("touch", onTouch) timer.performWithDelay( 1000, spawn, 0 )