Reputation: 5243
In my game I've a gamefield object (table) which contains all other graphic (display.newRect) and non graphic objects. Now I'm looking for good way to restart game, is there way to remove only gamefield object (table) and cause that inserted objects will be removed, graphic and non graphic together? Or I should remove graphic objects manually? Thank you.
Upvotes: 0
Views: 136
Reputation: 3030
Put all your graphical objects in a display group (display.newGroup). When you remove the display group, it will remove all the images, rects, etc.
You can add other attributes to the display group (i.e. use it as your gamefield object).
If you do it this way, you just need to remove the group (group:removeSelf()) and create a new one.
Upvotes: 1
Reputation: 5525
You need to create a method for the table (eg destroy()) that would traverse it and remove objects from the scene.
You would want to create a metatable for gamefield tables and call your method in __gc metamethod, if you're using Lua 5.2.1. If not, just call it explicitly.
Upvotes: 2