Storyboard newbie, can't figure this out..

Hi there!

Using the basic storyboard template… I’m having all my objects, functions, listeners, graphics and everything put within the createscene function…

Then when I want to restart the scene, wouldn’t it just be enough to call removeScene() and then go to the same scene again?

Everything just freeze up…

Do I need to manually remove ALL objects, timers and so on with a cleanup function before-hand…?

Can’t get the logic really…

Help would be much appreciated!

Thanks! [import]uid: 187595 topic_id: 32504 reply_id: 332504[/import]

Your display objects should be inserted into the scene.view(which is called ‘group’ in the template). They can also be inserted into a different group as long as you in turn insert that group into the scene.view group. As long as you do that then storyboard will handle disposing of your display objects for you.

As far as timers and Runtime event handlers, you will need to manually cancel/remove those in your destroy scene function.

Lastly, I am pretty sure you can’t change to the same scene you are already in. I might be wrong on that and maybe I just ran into issues with it, but anyways what I do is just have a blank scene that I change to and then I move back to my original scene. Works fine. [import]uid: 147305 topic_id: 32504 reply_id: 129279[/import]

I generally put things like images and such in createScene() and let the system destroy them when the scene is removed.

For things like timers, runtime listerens, I tend to turn them on in enterScene() since you don’t necessarily want them running until the scene is on the screen.

For things created in enterScene() (i.e. the timers and such) I remove in exitScene().

If I do something in createScene() that won’t be cleaned up automatically, I remove it during destroyScene(). They kinda go together.

Now Storyboard holds onto its information until they are automatically removed due to a low memory event or you explicitly purge/remove them.

Storyboard’s event handlers like createScene() and eventScene() can’t be called directly because the event structure isn’t setup and you can’t call them like a traditional function. You would have to generate the event using dispatchEvent (I think).

And I don’t think you can have a scene call itself as @budershank said. [import]uid: 19626 topic_id: 32504 reply_id: 129282[/import]

There is a reloadScene() function which is what I think you are after. However, for me this has been broken in recent daily builds. I have logged a bug but as far as I know it has not been resolved. Might work for you.

You can call the scene functions directly which is my work around for the reloadScene issue - these can be called with:

scene:exitScene()
scene:willEnterScene()
scene:enterScene()

Of course you may/not need all of those depending upon which you are using.

As others have mentioned you will need to take care of removing event handlers cancelling timers and transitions etc. [import]uid: 106799 topic_id: 32504 reply_id: 129285[/import]

The way I do it, if I have a addEvent then I have a removeEvent.

All performWithDelay commands use a variable, so I can stop them on exitScene.

All graphics go into the scene view group and I don’t remove them or destroy them.

On the game am working on at the moment, I can destroy the scene and go back into it many times without any problems.

This is what I have at the bottom of maingame.lua -

function scene:didExitScene( event )  
 storyboard.purgeScene( "maingame" )  
end  

So every time you quit the game back to the title screen, it gets rid of it. This is because things can change graphically in other parts of the app that effects maingame.lua

Dave [import]uid: 117617 topic_id: 32504 reply_id: 129291[/import]

Thank for all the feedback!

I’m trying to implement this now… However, I have lots of object, functions and event listerners… Loosing track on what is still in the memory and causes the freeze…

Is there any way of seeing what things are still in memory?

Also… Should all the unloading/cleanup code into the level1.lua or should I put all the clean-up code for all the scenes in main or menu.lua?

Thanks! [import]uid: 187595 topic_id: 32504 reply_id: 129329[/import]

Your display objects should be inserted into the scene.view(which is called ‘group’ in the template). They can also be inserted into a different group as long as you in turn insert that group into the scene.view group. As long as you do that then storyboard will handle disposing of your display objects for you.

As far as timers and Runtime event handlers, you will need to manually cancel/remove those in your destroy scene function.

Lastly, I am pretty sure you can’t change to the same scene you are already in. I might be wrong on that and maybe I just ran into issues with it, but anyways what I do is just have a blank scene that I change to and then I move back to my original scene. Works fine. [import]uid: 147305 topic_id: 32504 reply_id: 129279[/import]

I generally put things like images and such in createScene() and let the system destroy them when the scene is removed.

For things like timers, runtime listerens, I tend to turn them on in enterScene() since you don’t necessarily want them running until the scene is on the screen.

For things created in enterScene() (i.e. the timers and such) I remove in exitScene().

If I do something in createScene() that won’t be cleaned up automatically, I remove it during destroyScene(). They kinda go together.

Now Storyboard holds onto its information until they are automatically removed due to a low memory event or you explicitly purge/remove them.

Storyboard’s event handlers like createScene() and eventScene() can’t be called directly because the event structure isn’t setup and you can’t call them like a traditional function. You would have to generate the event using dispatchEvent (I think).

And I don’t think you can have a scene call itself as @budershank said. [import]uid: 19626 topic_id: 32504 reply_id: 129282[/import]

There is a reloadScene() function which is what I think you are after. However, for me this has been broken in recent daily builds. I have logged a bug but as far as I know it has not been resolved. Might work for you.

You can call the scene functions directly which is my work around for the reloadScene issue - these can be called with:

scene:exitScene()
scene:willEnterScene()
scene:enterScene()

Of course you may/not need all of those depending upon which you are using.

As others have mentioned you will need to take care of removing event handlers cancelling timers and transitions etc. [import]uid: 106799 topic_id: 32504 reply_id: 129285[/import]

The way I do it, if I have a addEvent then I have a removeEvent.

All performWithDelay commands use a variable, so I can stop them on exitScene.

All graphics go into the scene view group and I don’t remove them or destroy them.

On the game am working on at the moment, I can destroy the scene and go back into it many times without any problems.

This is what I have at the bottom of maingame.lua -

function scene:didExitScene( event )  
 storyboard.purgeScene( "maingame" )  
end  

So every time you quit the game back to the title screen, it gets rid of it. This is because things can change graphically in other parts of the app that effects maingame.lua

Dave [import]uid: 117617 topic_id: 32504 reply_id: 129291[/import]

Thank for all the feedback!

I’m trying to implement this now… However, I have lots of object, functions and event listerners… Loosing track on what is still in the memory and causes the freeze…

Is there any way of seeing what things are still in memory?

Also… Should all the unloading/cleanup code into the level1.lua or should I put all the clean-up code for all the scenes in main or menu.lua?

Thanks! [import]uid: 187595 topic_id: 32504 reply_id: 129329[/import]

Hi,

I already had some behavior like this when I manually inserted a “touch” event listener and then forgot to distinguish between event.phases in the “released” function. To put it into an exemple:

local function itemReleased( event )  
 if event.phase == "ended" then  
 -- change to newScene  
 end  
end  
  
-- somewhere inside the code  
 item:addEventListener( "touch", itemReleased )  

If you forget the if event.phase == "ended" then, the code will be performed twice. Once on

event.phase == "began" and once on "ended" resulting in the new scene being generated twice as well.

Perhaps this helps. [import]uid: 21480 topic_id: 32504 reply_id: 131704[/import]

Hi,

I already had some behavior like this when I manually inserted a “touch” event listener and then forgot to distinguish between event.phases in the “released” function. To put it into an exemple:

local function itemReleased( event )  
 if event.phase == "ended" then  
 -- change to newScene  
 end  
end  
  
-- somewhere inside the code  
 item:addEventListener( "touch", itemReleased )  

If you forget the if event.phase == "ended" then, the code will be performed twice. Once on

event.phase == "began" and once on "ended" resulting in the new scene being generated twice as well.

Perhaps this helps. [import]uid: 21480 topic_id: 32504 reply_id: 131704[/import]