so i have this function and it works but i needed to change it a bit and it doesnt works…
local onCollision = function(self, event) if event.phase == "began" then local hit = self.value local other = event.other.value if other == 1 then -- "1" is the value of the floor.. display.remove(ball[hit]) -- hit is the self value for the ball end return true end end function spawnBall() spawn = math.random(display.contentWidth \* 0.05, display.contentWidth \* 0.95) ball[i] = display.newImageRect("snowball.png", 50, 50 ) ball[i].x = spawn ball[i].y = -100 ball[i].collision = onCollision ball[i]:addEventListener( "collision", ball[i] ) end startTimer = timer.performWithDelay( 700, spawnBall, -1 )
but i changed it to this so it fitted my needs and now it doesnt detect a collision
local tb1 = {} function tbl:onCollision( self, event ) if event.phase == "began" then local hit = self.value local other = event.other.value if other == 1 then display.remove(ball[hit]) end return true end end function spawnBall() spawn = math.random(display.contentWidth \* 0.05, display.contentWidth \* 0.95) ball[i] = display.newImageRect("snowball.png", 50, 50 ) ball[i].x = spawn ball[i].y = -100 ball[i].collision = onCollision ball[i]:addEventListener( "collision", ball[i] ) end startTimer = timer.performWithDelay( 700, spawnBall, -1 )
NOTE : I DID REMOVE ALOT OF CODE FOR THE BETTER UNDERSTANDING SO IF SOMETHINGS NOT THERE IT DOESNT MEAN I DONT HAVE IT IN THE ORIGINAL