Your approach is essentially correct. I usually add my animated sprites to a table like “animObjects” and then, when I remove one particular animated object from the scene/stage (or if I pause it), I delete it from the table as follows (this is just one method; you can write your own):
[lua]
local function removeID( tableID, objID )
for i=1,#tableID do
local v = tableID[i] ; if ( v and v == objID ) then table.remove( tableID,i ) ; break end ; v = nil
end
end
removeID( animObjects, myObject )
[/lua]
Or, loop through the entire table to pause/play everything:
[lua]
if ( #animObjects > 0 ) then for j=1,#animObjects do animObjects[j]:play() end end
[/lua]
I suppose the “if” check isn’t really necessary, as Lua will just continue on its way in the case of a loop of 0 items.
Your approach is essentially correct. I usually add my animated sprites to a table like “animObjects” and then, when I remove one particular animated object from the scene/stage (or if I pause it), I delete it from the table as follows (this is just one method; you can write your own):
[lua]
local function removeID( tableID, objID )
for i=1,#tableID do
local v = tableID[i] ; if ( v and v == objID ) then table.remove( tableID,i ) ; break end ; v = nil
end
end
removeID( animObjects, myObject )
[/lua]
Or, loop through the entire table to pause/play everything:
[lua]
if ( #animObjects > 0 ) then for j=1,#animObjects do animObjects[j]:play() end end
[/lua]
I suppose the “if” check isn’t really necessary, as Lua will just continue on its way in the case of a loop of 0 items.