Storyboard API Questions

Jonathan:
Where do the ‘scenes’ sit in the overall display hierarchy? Or, to ask more directly:
I’d like to have a common background bitmap shown on of my scenes, without the memory and performance expense of re-loading it as a new bitmap on each scene.

When I attempt to place the bitmap before loading the first scene, I don’t see any of the scene content.
??

Thanks
[import]uid: 31041 topic_id: 17828 reply_id: 68225[/import]

@risingfrom, thank you so much for the code – it’s awesome! But now, you’ve made me feel torn between converting from Director to Storyboard API. (Converting means tons of work and tons of testing, but converting also means it’s possible to add swipe-effect… what do I do…?)

Thanks again!
Naomi [import]uid: 67217 topic_id: 17828 reply_id: 68226[/import]

Regarding the swipe question, looks like someone beat me to it! That’s exactly how I’d recommend doing it, so thanks @risingfrom.

To answer your question about modules.

When you call storyboard.removeScene( “myScene” ), that module IS completely removed from memory. When you call storyboard.gotoScene( “myScene” ), the module is then reloaded (as if it was the first time you loaded it). It is only when you call storyboard.purgeScene( “myScene” ) that the module is not unloaded (only the scene.view display group).

@scott0: That’s actually a bug that I’ve already fixed over here (along with a bunch of other good stuff, which I’ll get into in a moment), so stay tuned for an update that will fix the ‘objects on top’ issue. When the daily build with the update is available, you’ll simply create the background object before the ‘require “storyboard”’ line in main.lua.

If you can’t wait for the update (should be out within the next couple daily builds), then currently, in the version that’s out now, the scenes sit just below everything you might’ve created in main.lua, so if you want something to go behind your scenes when using storyboard, you can do something like this:

local storyboard = require "storyboard"storyboard.gotoScene( "scene1" )-- create imagelocal background = display.newImage( "bg.png" )-- do a timer delay or it won't worktimer.performWithDelay(1, function() display.getCurrentStage():insert( 1, background )end, 1 )[/code]Before the update gets checked-in (should be very soon), you'll have to do that whenever you do a scene change, so you may want to store a reference to your background object in the storyboard table. I recommend waiting until the daily build with the fix comes out before setting a background image though, so you don't have to go back and modify your code.Quick Update on What's Coming The following new things should be available soon, within the next few Daily Builds.New Effects Currently, all of the available effects will leave the current scene in place. However, due to popular demand, I've added some 'sliding' effects that will push the original scene over:slideLeftslideRightslideDownslideUpNew Functions storyboard.purgeAll() - purges all loaded scenes (except for the current scene).storyboard.removeAll() - removes all loaded scenes (except for the current scene).storyboard.getPrevious() - returns the previous scene name (as a string).storyboard.getScene( sceneName ) - returns the specified sceneName's scene object.New Feature In the upcoming update, you will be able to optionally specify a 'sceneName' when calling storyboard.newScene(), so scenes do not actually HAVE to be attached to external modules. For examples, you can create three (or more) different scene objects in one module, and just assign the appropriate listeners to them as you would other objects! (for scene events, of course).This is a special-use feature, as most will probably be sticking to the scene-per-module method, where no sceneName is specified in your call to storyboard.newScene() — as you are doing now.-----I'll update this thread (and the documentation pages) once a Daily Build with these changes is available for download.Thanks for the feedback/questions everyone! [import]uid: 52430 topic_id: 17828 reply_id: 68244[/import]

Hey Jon,

Thank you for the Good NEWS!

I have a question reagarding already the new APIs you said will be out soon. So its about the storyboard.getPrevious() and storyboard.getScene()

How about using these new APIs mentioned above regarding the storyboard.removeScene() and storyboard.purgeScene()?

When I call from a scene storyboard.getPrevious() for example, will the storyboard call the purge or remove scene functions if I have it set in my scene.lua file or as I`ve used the getScene() or getPrevious() the purge or remove functions will be ignored?

Tip: I am thinking about these new APIs (getScene and previousScene) as it would get the called scenes via some kind of “buffer” and so it would ignore any function of purgeScene or removeScene. Does it make sense for you?
Thank in advance.

Rodrigo. [import]uid: 89165 topic_id: 17828 reply_id: 68246[/import]

@RSCdev: I’m not exactly sure what you’re asking, but the new functions you mentioned are there to mainly get a reference to other scenes.

storyboard.getPrevious() will return a string of the scene name (since all scenes must have a unique name). This is used mainly if you do not know what scene you came from (e.g. your app goes to a random scene), it is useful for getting the scene name so you can purge it or remove it if necessary.

storyboard.getScene() will take one argument, sceneName, that retrieves the scene object that has a name matching the one you specified. A common use for this would be if you have a function in a specific scene module that you need to access, you can call storyboard.getScene() to get a reference to your scene, and then get a reference to the function/variable you need.

Neither of the functions affect storyboard.purgeScene() or storyboard.removeScene().

UPDATE: We *just* pushed in the changes, so the updates should be in the next Daily Build. The API documentation pages have been updated.

Here’s the index page:
http://developer.anscamobile.com/content/storyboard [import]uid: 52430 topic_id: 17828 reply_id: 68263[/import]

Jon,

Many thanks for that such a nice explanation.

I think you understood well what I`ve said above. I think I got it too but will see the next daily build so to confirm. :slight_smile:

Cheers,
Rodrigo. [import]uid: 89165 topic_id: 17828 reply_id: 68269[/import]

So, I’m still not sure what method gets called after you gotoScene(). For Director, you had a new() method that returned a group. I’m assuming for this we have a method that calls other methods that returns scene at the end like in scene1.lua.

Could someone clarify this?

scene1.lua is found in the “Common Storyboard API Questions” blog. [import]uid: 103624 topic_id: 17828 reply_id: 68294[/import]

@ jonathanbeebe

Thanks for the response. I understand that the scene will be completely removed and then reloaded as a fresh file. I might not have been specific enough. I’m asking how the required modules will be handled when removeScene is called. Will they be unloaded from memory? Or are the supposed to be unload from memory? In essence when a scene is removed, is that kicked down the chain of required modules loaded?

for example if you had a set up like so:

moduleA
/
scene - moduleB - moduleD
\
moduleC

would removing the scene in turn remove the modules or just the reference to them? From my testing it seems like they are not removed just the reference to them is. The reference to them is restored when you reload the scene again, but does not call it as a fresh load. This is causing me to have errors with drawing images again upon reloading the scene.

I may be setting up my modules incorrectly… this has me stumped.
Any insight would be helpful. [import]uid: 10192 topic_id: 17828 reply_id: 68306[/import]

Yeah I was wondering about setting up external modules too. Can I still use the blog post A Better Approach to External Modules with Storyboard ? I want level files with just level specific like enemy positions etc but calling external modules with all the functions thats for all the levels etc what’s the best approach to this using storyboard? Thanks in advance [import]uid: 94536 topic_id: 17828 reply_id: 68312[/import]

@risingfrom: Looks like you found a bug! When you call storyboard.removeScene() on a specific scene, it’s supposed to completely unload the module — which wasn’t happening. Thankfully, it was an easy fix and should be in the *next* update (not 2011.688, but the one after that).

In the meantime, to get around this issue, all you have to do is set the ‘sceneName’ key in package.loaded to nil after calling storyboard.removeScene(). Here’s an example:

storyboard.removeScene( "myScene" )package.loaded["myScene"] = nil[/code]Once the Daily build (after 2011.688) comes out, the second line above won't be needed (but it won't break anything if you leave that in there, as long as it's always after a call to storyboard.removeScene).@ncass: For regular external modules (not scenes), the method described in 'A Better Approach to External Modules' is still valid. Also remember, with those modules, if you want to completely unload the module, you'll also set its entry in the global package.loaded table to nil as well.@lKinx: In the same blog post you mentioned, there's a question in the FAQ list that states: "What is the Director-equivalent to the new() function?"That should answer your question :-) [import]uid: 52430 topic_id: 17828 reply_id: 68340[/import]

I thought I was going crazy for a minute. I couldn’t get a scene to be removed and reloaded until I read this thread about a bug in build 688 and a quick fix for it. Got everything working now.

I’m using storyboard for scene management for my game and it’s awesome. I look forward to the bug fixes in future daily builds and thank you for the quick fix :wink:

[import]uid: 38820 topic_id: 17828 reply_id: 68354[/import]

The bug fix will be in the next daily build, as well as another important bug fixes (regarding some scene transition effects looking distorted), so be sure to get the *next* daily build! (after 2011.688).

UPDATE: Daily build 2011.689 is now available, and includes the storyboard.removeScene() bug fix, as well as a fix for the strange zooming issue during scene change. Highly recommended download:

http://developer.anscamobile.com/release/2011/689 [import]uid: 52430 topic_id: 17828 reply_id: 68448[/import]

I have found that some effects doesn’t have same behaviour, namely the new ones. slideLeft doesn’t behave as slideRight and same with slideUp and slideDown. slideLeft and slideUp have same effect and slideRight and slideDown are the same. slideRight and slideDown are not correct. Original scene is not pushed away, it’s just goes black. [import]uid: 40334 topic_id: 17828 reply_id: 68635[/import]

@eugen5: As soon as the new build went live, we realized our previous changes (that fixed the scene-zooming) affected the behavior of the new slide-based effects. Thankfully, it was a very easy fix and just waiting to push the update into the daily builds.

In the meantime, just recognize that if you use the slide-based effects they will look a little strange until you get one of the upcoming daily builds (possibly not the next one, but it’ll be in the release notes when it does get pushed in).

The next update also fixes an issue where the first scene cannot have an effect, so until you get the build with the next update, try not to specify an effect for your very first scene change (usually in main.lua).

Thanks! [import]uid: 52430 topic_id: 17828 reply_id: 68652[/import]

@jonathanbeebe: Thanks. No worries for me thou. I am not going live just yet. A note: you wrote that “the slide-based effects will look a little strange”. I must say I really like how “slideLeft” behaves right now. It might not been intentional but it’s a cool effect. It is somehow in between slideLeft (how intended) and fromLeft. [import]uid: 40334 topic_id: 17828 reply_id: 68702[/import]

Many thanks to Ansca for this advancement and to Ricardo for his director class. Great effort!
I have a game made of levels (scene 1,2,…i…,n-1,n) and when “game over” happens in scene i, I need to go back to scene 1 instead of going forward to scene i+1.

How do I clear memory in a net way from scene 1? It seems that adding storyboard.removeScene (“scenei”) for all the i to scene1 makes the trick but am not sure it is going to backfire some way.

Thanks again.
–> edit: got it, it is storyboard.purgeAll() implemented in daily build 689 already [import]uid: 67641 topic_id: 17828 reply_id: 69167[/import]

UPDATE: Daily Build 2011.691 is now up, and in this build, there are currently no known Storyboard API issues :slight_smile:

Thanks for all your help in tracking down and exposing the initial bugs everyone!

Quick link to the daily builds page:
http://developer.anscamobile.com/downloads/daily-builds [import]uid: 52430 topic_id: 17828 reply_id: 69322[/import]

Hi Jonathan,
I’ve found bug in storyboard when we create an object and place him outside of the “contentWith”, and use “slideLeft” or “slideRight” transition effect. All scene is placed wrong, shifted left.
I’ve added this code to “scene1.lua” in Ansca sample app.
“scene1.lua”

image1 = display.newImage( “bell.png” )
image1.x = display.contentWidth
screenGroup:insert( image1 )

I’ve also changed transition effect to “slideLeft”.

“bell.png” is some image. I sent bug report today with sample files (case #9848)

Maybe I’m doing some wrong, but with other effects with same code storyboard works fine [import]uid: 13367 topic_id: 17828 reply_id: 69348[/import]

@iciler: Which build are you using? With Daily Build 2011.691, I’m not able to reproduce your issue (added an image outside of contentWidth and used “slideLeft” effect).

There were some bugs having to do with the slide transitions in the previous builds just before 2011.691 … If you’re not using at least 691, please try it and let me know if you’re still having issues.

Thanks. [import]uid: 52430 topic_id: 17828 reply_id: 69380[/import]

Hi Jonathan! I’ve used 694, the last one. Now, I’m reinstalling Corona SDK, so we will see very soon what will happend. [import]uid: 13367 topic_id: 17828 reply_id: 69383[/import]