问题
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.
回答1:
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.
回答2:
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.
回答3:
You will need to remove them yourself.
来源:https://stackoverflow.com/questions/21505267/lua-delete-table-which-contains-graphic-objects