Lua : delete table which contains graphic objects

一笑奈何 提交于 2020-01-06 12:36:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!