So I cannot figure this out for the life of me… The program is simply a starter and its a test with manageing multiple instances of one object. So I want to remove the objects(Boxes in this case) that are being displayed individually but I dont know how to stick these objects into tables and then manipulate them to destroy them without removing the variable and causing an error.
Any Ideas?
Or any really easy solutions to handling this problem?
xAxis = 100 --Variable initiaions
yAxis = 100
local boxStorage = {}
function onObjectTouch( event )
if event.phase == “began” then
print( “Hello”)
table.remove(boxStorage)
box:removeSelf()
box = nil
end
return true
end
for i = 1, 20, 1 do
print(i)
if xAxis <= 668 then
box = display.newRect(xAxis , yAxis , 50 , 50)
box:addEventListener( “touch”, onObjectTouch )–Allows the object to be removed…
table.insert(boxStorage , box)
xAxis = xAxis + 100
end
if xAxis >= 669 then
xAxis = 100
yAxis = yAxis + 200
box = display.newRect(xAxis , yAxis , 50 , 50)
box:addEventListener( “touch”, onObjectTouch )
table.insert(boxStorage , box)
end
end