They both work like a charm thank you gents
Just one last question, here is what I ended up using. The stuff in bold is part of the code that I hadn’t included before. Basically it’s lines of cubes that go down, and once they reach the bottom they dissapear. You guys helped me with that, but I want them to reappear at the top, and change pictures…I tried calling the createCube1() on various places within the loop, but this increases and even multuplies the memory sometimes. Do guys have any suggestions on how to implement this?
myTable= {}
-----------CREATE ROW 1
for i = 1, 7, 1 do
square1 = display.newImageRect( images[math.random(1,9)], cubeDimension, cubeDimension)
square1.x = cubeDimension * (i)
square1.y = screenH - halfCube - (cubeDimension)
table.insert(myTable, square1)
end
------------ROW 2 Higher on the Y axis
for i = 1, 7, 1 do
square1 = display.newImageRect( images[math.random(1,9)], cubeDimension, cubeDimension)
square1.x = cubeDimension * i
square1.y = screenH - halfCube - (cubeDimension*2)
table.insert(myTable, square1)
end
--------------ROW 3
for i = 1, 7, 1 do
square1 = display.newImageRect( images[math.random(1,9)], cubeDimension, cubeDimension)
square1.x = cubeDimension * i
square1.y = screenH - halfCube - (cubeDimension*3)
table.insert(myTable, square1)
end
----------ROW 4
for i = 1, 7, 1 do
square1 = display.newImageRect( images[math.random(1,9)], cubeDimension, cubeDimension)
square1.x = cubeDimension * i
square1.y = screenH - halfCube - (cubeDimension*4)
table.insert(myTable, square1)
end
-----------function to create new line of cubes (it works, it’s just increasing memory probably because I’m not calling it in the right place)
function createCube1()
for i = 1, 7, 1 do
square1 = display.newImageRect( images[math.random(1,9)], cubeDimension, cubeDimension)
square1.x = cubeDimension * i
square1.y = screenH - halfCube - (cubeDimension*4)
table.insert(myTable, square1)
end
end
–boolean to help with above function
createCube = false
-----the…LOOP
local function loop()
for i = #myTable, 1, -1 do
local object = myTable[i]
if object ~= nil then
object.y = object.y + 5
end
if object.y > 834 then
myTable[i]:removeSelf()
table.remove(myTable,i)
object:removeSelf()
end
end
end
Runtime:addEventListener(“enterFrame”, loop)