Hi,
what I am trying to do is to have objects removed as when they pass the end of the screen and after they’ve been removed they will eventually be recreated at the top of the screen. This is where I’m stuck.
The code used to randomly spawn and create my objects (bubbles):
for i = 1, 15 do bubble[i] = display.newImage("img/bubble.png") physics.addBody( bubble[i], "static", {isSensor = true, radius = 26} ) bubble[i].x = math.random(1,6)\*100 bubble[i].y = math.random(1,10)\*-100 group:insert(bubble[i]) end for j = #bubble, 1 do if bubble[j].y \>= display.contentHeight then display.remove(bubble[j]) end end local moveBubbles = function( event ) for i = 1, #bubble do bubble[i].y = bubble[i].y + 20 end end local gameLoop = function ( event ) moveBubbles() end Runtime:addEventListener( "enterFrame", gameLoop)
Is the idea of removing and recreating items ineffecient, should I instead ‘load’ all of my objects and then just respawn them at a new location above the screen?The reason to why I want to remove & recreate new objects is because eventually I would like to recreate them in specific patterns created by unique pattern functions, but first I would need the recreation of the bubbles to work.
Glad if anyone could take their time to help, thanks in advance.