Posted on by
NOTE: This tutorial is outdated and has been replaced by resources in Corona University. Please refer to these guides and tutorials for current information and usage examples.

Posted by . Thanks for reading...

23 Responses to “Common Storyboard API Questions”

  1. Thy

    Great post! This helped clear some stuff up for me, especially the event listener/functions flow you did first. Thanks, and looking forward to using this!

    Reply
  2. Jonathan Beebe

    @Jason: Yes, if you call storyboard.gotoScene( “scene1″, “fade” ) while you are in scene1, then it will dispatch an “exitScene” event, and then transition to scene1 (again) and then dispatch an “enterScene” event.

    A “createScene” event won’t be dispatched at this point, that is, unless you purge the scene first (before calling storyboard.gotoScene()).

    Reply
  3. StefanHQ

    Regarding Scene effects: It would be good if there was some way of having more control over the animation of them.

    Right now the effects are very limited. Typical effects needed would be more ease-in / ease-out or the very common “bounce” in effects. This would make a huge difference to game quality.

    And also to control the function for both current and new scene (a & b in this example)

    1.Say adding the option to have a function controling the position/rotation/scale/fade to allow custom-coded transitions.

    storyboard.gotoScene( sceneName [, aFunction, bFunction, effectTime] )

    2. Another way instead of adding custom-coded transition effects for the scenes would be to not just allow the fading time but also the animation type. Say: easy-in/ease out, bouncy, bubble-motion, wobble etc.

    More parameter control of each effecttyp in other words :)

    ex:

    storyboard.gotoScene( sceneName [, effect, aAnimType, bAnimType, effectTime] )

    Reply
  4. StefanHQ

    Sorry, forgot to mention.

    Most of the time, you usaly want to let the scenes overlap on top och each other. A lot of the effect do not use the “(over original scene)” method. There would be much better to have a parameter setting if the scenes should “wait” for each other, overlap each other or push each other.

    But because this API now is released. The simplest (and maybe only) way now is to add more effect types. Not the most elegant & flexible solution. But at least it would not disturb the already present API.

    So more effectypes with (over original scenes and definately more transition types)

    (why did you use the word “effect” instead of the more commonly used “transition” especially regarding scenes/storyboards?)

    Reply
  5. Mike M

    I think the FAQ misses a further important question:

    What kind of Objekt do I have to remove manually?

    Because some Objects are not removed automatically by putting them into the scene group. For example the newEmbossedText.

    And it seems there is no way to remove a Mask of the scrollwiew widget. If I remove my scrollview like this:

    display.remove( scrollView )
    scrollView = nil

    the mask still remains in memory. How to fix that?

    Thanks

    Reply
  6. Mike M

    ok, the scrollView widet error was my fault. i made the scrollview local in my enterScene event :/ insted local in my scene file. Now the scrollview will removed completely.

    Anyhow, a list of objects I have to remove manually would be nice.

    Reply
  7. Nick

    Does anyone have hints for removing and restoring a tableView on scene change? My tableView appears correctly on first load (it is in the enterScene event) and is removed in the exitScene event; however, when visiting that scene again (via the tab bar), the tableView is not added appropriately. I receive an error that later in the code the tableView object is a nil value.

    The storyboard API and the tableView API both seem very cool, too bad they don’t work together so well yet.

    Reply
  8. Nick

    Hi everybody, just wanted to say that I fixed my problem. Thanks in general for this article, can it be added to the primary documentation to make it more searchable? (I couldn’t find it by searching the site!)

    Reply
  9. Kawika

    How is inneractive set-up with Storyboard. Prior to the Storyboard declaration (local storyboard = require “storyboard”) or after, when using ads in multiple scene’s?

    Reply
  10. Jammy

    Can I use storyboard in this way … I want to have a persistent background that goes between all levels. So basically my levels would be on top of my background that’s in main.lua. It seems that when you put the background image in main.lua, this sits on top of everything else on the display list. Any thoughts?

    Reply
  11. John Conti

    I have successfully worked around the problems with widgets in storyboard scenes as discussed above. My difficulty is that recreating my widgets for each scene means I have no caching of scenes as I had hoped to have from this api.

    My questions are then:
    1) Are there fixes in the works, soon?
    2) Can I construct my tableviews and cache them myself.
    3) If so, do I add and remove them to the view property to maintain the same ordering with respect to tabviews and masthead panels?

    Thanks,
    John

    Reply
    • Greg

      @John Conti – did you get a reply for your questions?

      @coronalabs – would appreciate a reply to John’s questions

      Reply
  12. Jason Presley

    I am not understanding the use of the storyboard and managing memory. I have created a little sample app to test memory usage but the results are not what I am expecting. Could someone please help point out the error in my code or straighten out my misconceptions on how this should work?

    Here is my sample app code:

    ———————————————–
    – main.lua
    ———————————————–
    display.setStatusBar( display.HiddenStatusBar )

    collectgarbage()
    local textMem = system.getInfo( “textureMemoryUsed” ) / 1000000
    print( “—————————————————” )
    print( “” )
    print( “Initial Memory Values: main.lua” )
    print( ” Memory Usage: ” .. collectgarbage(“count”) )
    print( ” Texture Memory: ” .. textMem )
    print( “” )

    local storyboard = require ‘storyboard’
    storyboard.gotoScene( “scene1″, “fade”, 400 )

    ———————————————–
    – scene1.lua
    ———————————————–
    local storyboard = require( “storyboard” )
    local scene1 = storyboard.newScene()

    function scene1:createScene( event )
    local grScene1 = self.view
    local dch = display.contentHeight
    local dcw = display.contentWidth

    light = display.newImage(“switchLightOn.png”)
    light.x = dcw/2
    light.y = dch/2
    grScene1:insert(light)

    function gotoScene2 (event)
    storyboard.gotoScene( “scene2″, “fade”, 400 )
    end
    end

    function scene1:enterScene( event )
    local grScene1 = self.view
    light:addEventListener(“tap”, gotoScene2)

    collectgarbage()
    local textMem = system.getInfo( “textureMemoryUsed” ) / 1000000
    print( “Scene1 Memory Values: Light Switch Image” )
    print( ” Memory Usage: ” .. collectgarbage(“count”) )
    print( ” Texture Memory: ” .. textMem )
    print( “” )
    end

    function scene1:exitScene( event )
    local grScene1 = self.view
    light:removeEventListener(“tap”, gotoScene2)
    grScene1 = nil
    end

    function scene1:destroyScene( event )
    local grScene1 = self.view
    grScene1 = nil
    end

    scene1:addEventListener( “createScene”, scene1 )
    scene1:addEventListener( “enterScene”, scene1 )
    scene1:addEventListener( “exitScene”, scene1 )
    scene1:addEventListener( “destroyScene”, scene1 )
    return scene1

    ———————————————–
    – scene2.lua
    ———————————————–
    local storyboard = require( “storyboard” )
    local scene2 = storyboard.newScene()

    function scene2:createScene( event )
    local grScene2 = self.view
    local dch = display.contentHeight
    local dcw = display.contentWidth

    bird = display.newImage(“bird.png”)
    bird.x = dcw/2
    bird.y = dch/2
    grScene2:insert(bird)

    function gotoScene3 (event)
    storyboard.gotoScene( “scene3″, “fade”, 400 )
    end
    end

    function scene2:enterScene( event )
    local grScene2 = self.view
    bird:addEventListener(“tap”, gotoScene3)

    collectgarbage()
    local textMem = system.getInfo( “textureMemoryUsed” ) / 1000000
    print( “Scene2 Memory Values: Bird Image” )
    print( ” Memory Usage: ” .. collectgarbage(“count”) )
    print( ” Texture Memory: ” .. textMem )
    print( “” )
    end

    function scene2:exitScene( event )
    local grScene2 = self.view
    bird:removeEventListener(“tap”, gotoScene3)
    grScene2 = nil
    end

    function scene2:destroyScene( event )
    local grScene2 = self.view
    grScene2 = nil
    end

    scene2:addEventListener( “createScene”, scene2 )
    scene2:addEventListener( “enterScene”, scene2 )
    scene2:addEventListener( “exitScene”, scene2 )
    scene2:addEventListener( “destroyScene”, scene2 )
    return scene2

    ———————————————–
    – scene3.lua
    ———————————————–
    local storyboard = require( “storyboard” )
    local scene3 = storyboard.newScene()

    function scene3:createScene( event )
    local grScene3 = self.view
    local dch = display.contentHeight
    local dcw = display.contentWidth

    bohr = display.newImage(“bohr.jpg”)
    bohr.x = dcw/2
    bohr.y = dch/2
    bohr:scale(.4, .4)
    grScene3:insert(bohr)

    function gotoScene1 (event)
    storyboard.gotoScene( “scene1″, “fade”, 400 )
    end
    end

    function scene3:enterScene( event )
    local grScene3 = self.view
    bohr:addEventListener(“tap”, gotoScene1)

    collectgarbage()
    local textMem = system.getInfo( “textureMemoryUsed” ) / 1000000
    print( “Scene3 Memory Values: Trading Card Image” )
    print( ” Memory Usage: ” .. collectgarbage(“count”) )
    print( ” Texture Memory: ” .. textMem )
    print( “” )
    end

    function scene3:exitScene( event )
    local grScene3 = self.view
    bohr:removeEventListener(“tap”, gotoScene1)
    grScene3 = nil
    storyboard.removeAll()
    end

    function scene3:destroyScene( event )
    local grScene3 = self.view
    grScene3 = nil
    end

    scene3:addEventListener( “createScene”, scene3 )
    scene3:addEventListener( “enterScene”, scene3 )
    scene3:addEventListener( “exitScene”, scene3 )
    scene3:addEventListener( “destroyScene”, scene3 )
    return scene3

    – END SAMPLE CODE

    When I run this app and click on each one of the images here I what I get in the simulator output window:

    Initial Memory Values: main.lua
    Memory Usage: 84.6044921875
    Texture memory: 0

    Scene1 Memory Values: Light Switch Image
    Memory Usage: 108.6572265625
    Texture memory: 0.008192

    Scene2 Memory Values: Bird Image
    Memory Usage: 112.470703125
    Texture memory: 0.540672

    Scene3 Memory Values: Trading Card Image
    Memory Usage: 116.2490234375
    Texture memory: 9.445376

    Scene1 Memory Values: Light Switch Image
    Memory Usage: 113.72265625
    Texture memory: 9.445376

    The first four outputs are as expected. Each time the scene changes and a new image is displayed the memory usage and texture memory increase. What I don’t understand is the last output block when I return to scene 1. In the exitScene function of scene 3 I have a storyboard.removeAll() function call. My understanding is that this would call the destroyScene method and remove everything from memory and free all the available memory. Thus my output readings for Scene 1 should be the same both times. The second output for scene 1 looks like no texture memory was freed up at all. What is the storyboard.removeAll() or the storyboard.purgeAll() functions doing? How do I free up memory when I leave a scene?

    Thanks,

    Jason Presley

    Reply
  13. nick g

    Jason
    Since your code isn’t formatted on here using the code tags, I can’t run it without running through….every…single…..line….and replacing quotes and removing extra characters like ? marks from copy and past..

    I think it supports code tags

    If you see that above, then it’s with code in between and then another with code in between the but with a /.

    Reply
  14. nick g

    Hmm, there are a lot of syntax errors. So try reposting using the code tags. I can’t post how to do that since when I do it hides it.

    Reply
  15. Jim W

    I am working with a few other people to build a Corona app. At this point, I am the only subscriber in the group. In the “Introducing StoryBoard” article, it says the API is “only available to subscribers”. Can you clarify that a bit? Does that mean a non-subscriber will not be able to run code that uses the StoryBoard API in their simulator (for testing, etc.)?

    Reply
  16. Brent Sorrentino

    Hello Jim W.,
    Thanks for your comment. Since the time this article was first written, Storyboard has been rolled out to the current Public Build… so, you are free to use it, test it, and include it in all of your apps, even if you’re not an Indie or Pro subscriber.

    Reply
  17. Justin M

    hey guys i really need help. so im making a game…i have a main.lua and game.lua that are being used so far. in my main.lua i have-

    local storyboard = require “storyboard”
    storyboard.gotoScene(“game”)

    and in my main.lua thats related to that ^ i have -

    local storyboard = require (“storyboard”)
    local scene = storyboard.newScene()

    anyway when i save and try to open to make my game work i get a runtime error saying that in the second line storyboard.gotoScene(“game”) it attempts to index local storyboard
    can someone please help me fix this

    Reply

Leave a Reply

  • (Will Not Be Published)