I’m currently trying to replicate “Swipe Brick Breaker” a clone of one of the games made by 111% games.
https://www.youtube.com/watch?v=NrjuN6Vx7KM
<------ (this is what I’m trying to make)
I currently have 3 balls moving on screen and I would like them to stop moving and get deleted when they reach the bottem of the screen. The balls are being iterated through a ballTable with the enterFrame listener so that they can all move. I thought removing the ball being iterated with removeSelf() and then setting the ball to be = nil would allow me to do this (as I have an if ball ~= nil statement which should bypass the function if ball = nil). Here’s what I have:
[spoiler]
function updatenewbullet() for key,ball in pairs(ballTable) do if ball ~= nil then -- don't do rest of function is ball is nil? NOT WORKING -- Movement ball.x = ball.x + ball.velocityX ball.y = ball.y + ball.velocityY -- If ball hits the ceiling or left or right wall, bounce off of it if ball.x \< 0 or ball.x + ball.width \> display.contentWidth then ball.velocityX = -ball.velocityX end -- Bounce off top wall if ball.y \< -30 then ball.velocityY = -ball.velocityY end -- stop if ball reaches bottem wall if ball.y \> display.contentHeight + 20 then ball.velocityY = 0 ball.velocityX = 0 ball:removeSelf() -- remove ball ball = nil -- set ball to nil end end end end
As shown I have set my ball to nil when it’s reached the bottem of the display but function continues despite the “if ball ~= nil then” and the ball being nil.
[/spoiler]