Yes, I removed it from the most recent version. Though, according to the garbagecollect if you do nil out those variables you do eek out a little more memory if for some reason you were really desperate. It saves only a very tiny amount of space though.
I think I worked out a naming function for the objects that the loop produces, but when I send that to the remove function it only removes the first object that hits the bottom of the display.
my code:
[code]
local j = 0
local k = 0
local nameHolder
local nameRemover
local physics = require(“physics”)
physics.start()
physics.setGravity( 0, 0 )
local x = 50
local background = display.newImage(“background.png”)
allBall = {}
local function removeByName( allBall, nameRemover )
for i,v in ipairs( allBall ) do
if ( v ~= nil and v == nameRemover ) then
allBall[i] = nil ; break
end
end
end
local function addByName( allBall, nameHolder )
local vCount = 0
for i,v in ipairs( allBall ) do
if ( v == nameHolder ) then
vCount = vCount+1
end
end
if ( vCount == 0 ) then
allBall[#allBall + 1] = nameHolder
end
end
local function randomBall ()
j = j + 1
if x < 3000 then
local imageBall = display.newImage( “ball.png” )
allBall[#allBall + 1] = imageBall
local oneBall = allBall[#allBall]
oneBall.myName = “ball” … j
nameHolder = oneBall.myName
addByName( allBall, nameHolder )
local randomPos = math.random
oneBall.x = 10 + randomPos( 300 ); oneBall.y = -20
physics.addBody( oneBall, { density=2.9, friction=0.0, bounce = 0 } )
oneBall:setLinearVelocity( 0, 600 )
end
local function removeOffscreenItems()
for i = 1, #allBall do
local oneBall = allBall[i]
if ( oneBall.x ) then
if ( oneBall.y > display.contentHeight + 30 ) then
k = k + 1
oneBall.myName = “ball” … k
nameRemover = oneBall.myName
removeByName( allBall, nameRemover )
oneBall:removeSelf()
oneBall = nil
y = y - 1
end
end
end
end
Runtime:addEventListener( “enterFrame”, removeOffscreenItems )
end
y = 11
local timberBall = timer.performWithDelay( x, randomBall, y )
[/code] [import]uid: 10903 topic_id: 3378 reply_id: 11951[/import]
[import]uid: 11636 topic_id: 3378 reply_id: 15873[/import]