WHat's best practice for adding and removing physics bodies?

I have a simple game set up with one level. I want to add more levels. To do this I need to clean up and remove all of the bodies created for the previous level and then create and set up the new bodies for the next level. What's the best practice here?

When the game starts I create all of the bodies used in the level and add them to an array. As the game plays bodies are eliminated. Rather than removing these I set their isActiveBody property to false and move them off the screen. When the level ends I loop through my array and call removeSelf() on each body that was created. Then I move on and create the bodies used in the next level.

If anyone has any pointers on memory management and best practice to handling removing elements and making sure that they don't cause memory leaks I'd like to here them.

Your method sounds fine.

Use display.remove as opposed to removeSelf would be one of my suggestions however :)

What's the difference between display.remove() and removeSelf()?

views:1403 update:2012/1/4 9:12:54
corona forums © 2003-2011