there are different ways to remove objects. the easiest way is doing:
local function removeCircle(varIn) local var=varIn display.remove(multipleCircles[var]) -- it checks internally if it exists or not multipleCircles[var]=nil end
the other metod was the one i puted in my code.
if you want to delete all objects at the end you should remove them all in another function:
local function removeAllCircle() for i=#multipleCircles, 1, -1 do if multipleCircles[i] then multipleCircles[i]:removeSelf() multipleCircles[i]=nil end end multipleCircles=nil end
or:
local function removeAllCircle() for i=#multipleCircles, 1, -1 do display.remove(multipleCircles[i]) multipleCircles[i]=nil end multipleCircles=nil end
just remember to use backwards cicle when you are deleting tables.
if your objects have more things attach to them i usually remove them too, before the last step (removeSelf()). for example if they have touch events, i remove first the touch event for that object then i remove the object.
If i good understand, it’s a bad pratice to create/destroy physics objects but it’s encouraged when you don’t use physics object ?
depends when you want to destroy them and the number of objects to delete or create. my first way of thinking is always to clean what is not showned anymore. but if that process creates overhead, just hidden them is a better aproach in that case. complex objects that are “hard” to create, if your constant needing them, hidden them is one way to go.
just remember that hidden objects don’t remove them from memory.
remember too, that creating and removing objects uses more cpu power than just hidden them.
when you create and remove objects creates lag on your app, maybe the problem is not removing or creating the objects…are in the rest of the code, but that really depends on when and how many are you deleting and creating.