Question About Storyboard And Enter/leave Scene

Hi, im having a hard time trying to do something it might be easier in another way.

Basically, what i have is:

-main.lua : where i just gotoscene “level01” and some other random stuff

-level01: display objects, audio, function to go level 02, other functions

-level02: same as level 01 but function to go level 01

Now i’m having some questions about display objects/audio/even listeners changing scenes.

I want to change between level01 and level02 (basic interaction is done) but load the level again if i want to. For example, im on level 01,changes to level 02 (level 01 gets destroyed). But during level 02 i want to go back to level01 and create all the display objects / load audios / etc.

I tried putting all that into the enterscene function but i have problems with other functions in the module, specially when i make a evenlistener such as (button01:addEventListener(“touch”,x)) and button01 is declared inside the enterscene function.

I don’t know if i’ve explained it ok, but any help is appreciated.

Thanks.

First unless you expressly call a function to purge the scene (or you have autopurge on), then when you leave level01 to go to level02, level01 stays in memory, it’s just hidden off screen.  Because of this, all of the things you create in createScene for level01, will still be there when you goto level01 again.   If a low memory event is triggered, storyboard will purge off screen scenes.  

If leve01 gets purged and you storyboard.gotoScene(“level01”) then the createScene() function gets called and things get re-created.

Regardless of the need to call createScene or not, enterScene is called every time a scene is entered.  You can choose to do everything in enterScene() (and cleanup in exitScene()) but if you do, no scene transitions will work.  They required scene creation be done in createScene then that scene is transitioned on screen while the previous scene is moved off screen.  Once this transition is done, enterScene gets called.

enterScene and exitScene work in pairs.  For every enterScene there will be an exitScene.  For every createScene, if purging happens there will be a matching destoryScene.

The result of this is if you create it in createScene (and it’s not something automatically cleaned up for you) then you need to remove it in exitScene).  See this week’s blog post on cleaning up scenes:  http://www.coronalabs.com/blog/2013/04/02/cleaning-up-display-objects-andlisteners/

If you create something in enterScene that needs manual clean up, then do that in exit Scene.

I ended up re-reading that link and every single guide about storyboards, and finally made it work. 

Thanks for the tips, Rob.

Hi, i finally made it, but somehow whenever i run it on the device, its lagging like hell, wich is weird because im using just 6 (20kb ea) images and 4mb of sounds.

This is the structure im using:

-main: just gotolevel01

-level01:

createScene: loads audio

enterScene: all display objects and eventlisteners, group’d in local group = self.view, purgesScene (previous and next one, for example level03 purges 02 and 04)

destroyScene: dispose audios and removes eventListeners

I’m testing it with the FPS module and its giving me 1-5fps when i change from scene to scene on the phone (its ok on simulator ofc, but it lags a little bit)

Trying at the moment a bunch of other methods but it justs keeps lagging whenever i change scenes or use audio (app atm does just that … ).

Can you tell if i’m doing anything wrong? or any tip about fps and storyboard api?

Thanks in advance.

Can you post some code?

First unless you expressly call a function to purge the scene (or you have autopurge on), then when you leave level01 to go to level02, level01 stays in memory, it’s just hidden off screen.  Because of this, all of the things you create in createScene for level01, will still be there when you goto level01 again.   If a low memory event is triggered, storyboard will purge off screen scenes.  

If leve01 gets purged and you storyboard.gotoScene(“level01”) then the createScene() function gets called and things get re-created.

Regardless of the need to call createScene or not, enterScene is called every time a scene is entered.  You can choose to do everything in enterScene() (and cleanup in exitScene()) but if you do, no scene transitions will work.  They required scene creation be done in createScene then that scene is transitioned on screen while the previous scene is moved off screen.  Once this transition is done, enterScene gets called.

enterScene and exitScene work in pairs.  For every enterScene there will be an exitScene.  For every createScene, if purging happens there will be a matching destoryScene.

The result of this is if you create it in createScene (and it’s not something automatically cleaned up for you) then you need to remove it in exitScene).  See this week’s blog post on cleaning up scenes:  http://www.coronalabs.com/blog/2013/04/02/cleaning-up-display-objects-andlisteners/

If you create something in enterScene that needs manual clean up, then do that in exit Scene.

I ended up re-reading that link and every single guide about storyboards, and finally made it work. 

Thanks for the tips, Rob.

Hi, i finally made it, but somehow whenever i run it on the device, its lagging like hell, wich is weird because im using just 6 (20kb ea) images and 4mb of sounds.

This is the structure im using:

-main: just gotolevel01

-level01:

createScene: loads audio

enterScene: all display objects and eventlisteners, group’d in local group = self.view, purgesScene (previous and next one, for example level03 purges 02 and 04)

destroyScene: dispose audios and removes eventListeners

I’m testing it with the FPS module and its giving me 1-5fps when i change from scene to scene on the phone (its ok on simulator ofc, but it lags a little bit)

Trying at the moment a bunch of other methods but it justs keeps lagging whenever i change scenes or use audio (app atm does just that … ).

Can you tell if i’m doing anything wrong? or any tip about fps and storyboard api?

Thanks in advance.

Can you post some code?