Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local director, coronaMetaTable = {scene = 'main'}, getmetatable(display.getCurrentStage())
- local function cleanGroups (object)
- if type(object) ~= 'table' or getmetatable(object) ~= coronaMetaTable then return end
- if object.numChildren then
- while object.numChildren > 0 do
- cleanGroups(object[object.numChildren])
- end
- end
- object:removeSelf()
- end
- function director:changeScene (moduleName)
- if type(moduleName) == 'nil' or self.scene == moduleName then return end
- local loadedModule = package.loaded[self.scene]
- if type(loadedModule) == 'table' and loadedModule.clean and type(loadedModule.clean) == 'function' then
- loadedModule.clean()
- end
- cleanGroups(self.view)
- if self.scene ~= 'main' and type(loadedModule) == 'table' then
- package.loaded[self.scene], loadedModule = nil
- collectgarbage('collect')
- end
- self.view, self.scene = require(moduleName).new(), moduleName
- end
- return director
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement