Corona Display Groups Creation and Removal in Storyboard

Hello,

I’m having some trouble with display groups using storyboard. Anyway, I have 1 display group that I create outside of createscene().

local foreground = display.newGroup()
 

In createscene(),  I insert it to the scene’s group so that it becomes a child of it.

group:insert(foreground)
 

In exitscene(), I do foreground:removeSelf(0

This properly removes the foreground and all of its objects. However, because I declared the display group outside of createscene(), I don’t know how to make the scene declare the groups again when I get back to the scene, since I’m declaring it outside of createscene().

I can’t put local foreground = display.newGroup() inside of createscene because existscene() won’t detect it, and I heard it’s bad practice to make it global.

So I was looking for some suggestions on how I could approach this particular problem i have.

Thanks.

Do you need scenes to stay in memory when they’re not being used? 

If not, just call this at the top of each scene, then when you go back to a scene it will load from scratch as before.

[lua]

 storyboard.removeAll()

[/lua]

You don’t need to do foreground:removeSelf() in exitscene() either, it will automatically be removed when you goto another scene.

Unfortunately I need a few oop scenes and variables open for re-using. RemoveAll() removes everything essentially and it causes problems on reload.

I don’t use the “local” prefix for my storyboard sub-groups and I call them all in the create scene. I nest them into my main storyboard scene group, so once that’s disposed of at the end of the scene all the other groups are also automatically removed.

I see. I tend to keep everything in each scene self-contained. If I need variables or functions available throughout the app, I create a functions.lua and globals.lua file to hold those.

i.e.

[lua]

local glo = {}

glo.sound = 0.7

glo.touchAllowed = false

return glo

[/lua]

Then I put this in main.lua:

[lua]

glo = require(“globals”)  

[/lua]

That helped. Thanks.

Do you need scenes to stay in memory when they’re not being used? 

If not, just call this at the top of each scene, then when you go back to a scene it will load from scratch as before.

[lua]

 storyboard.removeAll()

[/lua]

You don’t need to do foreground:removeSelf() in exitscene() either, it will automatically be removed when you goto another scene.

Unfortunately I need a few oop scenes and variables open for re-using. RemoveAll() removes everything essentially and it causes problems on reload.

I don’t use the “local” prefix for my storyboard sub-groups and I call them all in the create scene. I nest them into my main storyboard scene group, so once that’s disposed of at the end of the scene all the other groups are also automatically removed.

I see. I tend to keep everything in each scene self-contained. If I need variables or functions available throughout the app, I create a functions.lua and globals.lua file to hold those.

i.e.

[lua]

local glo = {}

glo.sound = 0.7

glo.touchAllowed = false

return glo

[/lua]

Then I put this in main.lua:

[lua]

glo = require(“globals”)  

[/lua]

That helped. Thanks.