Trying to Learn Storyboard

Hi all,

I am working on my first app and am trying to learn the Storyboard API. I think I’m beginning to understand how to use each listener function. Maybe.

What I’m still trying to understand is why (in the sample code included with Corona) are the local variables and, especially, the onSceneTouch function declared OUTSIDE of the listener functions “createScene” or “enterScene?”

The notes in the template say “–Some things you might want to do in the “enterScene” event listener include things like positioning objects in specific places, show a message to the user, start physics, add event listeners (touch, enterFrame, etc), etc.”

HOWEVER, what I think I see is that the onSceneTouch listener function is defined outside of everything else and then assigned to image.touch in the “createScene” function. Why is it not done in the “enterScene” function, as the notes suggest?

I think I might understand the template better if the code showed individual buttons used to change scenes. Maybe.

All I’m really trying to do at this point is to put my simple game code in scene1 and then create a scene2 (as a sceneOverlay) for game options such as restart, resume, etc. But before I get there, I’m trying to learn the Storyboard API first.

ANY suggestions, examples, links, or comments are greatly appreciated. Thank you in advance!

-Mat [import]uid: 70259 topic_id: 28620 reply_id: 328620[/import]

If you create a function inside of createScene (with a local at the beginning), then that function is NOT available to enterScene because of scoping rules. Creating a global function inside of an event handler like createScene is simply bad programming practice.

Also don’t confuse the function that holds the function’s contacts and the assignment of that function to an event listener.

Also keep in mind that things like touch handlers that get assigned to objects get automatically removed when the object does. Runtime listeners however do not automatically get removed. I have no issues creating the event listener for objects in createScene. It makes more sense to do them there. However your Runtime listeners need to be done in enterScene and removed in exitScene.

Start physics in enterScene, end physics in exitScene [import]uid: 19626 topic_id: 28620 reply_id: 115434[/import]

Thanks much. Your explanation is very helpful. [import]uid: 70259 topic_id: 28620 reply_id: 115565[/import]

OK. I’m making progress. I am successfully setting and getting variables and using them between Storyboard scenes with showOverlay and hideOverlay. Thanks for your help.

I am able to pause and resume physics using the overlay scene as an options screen. Wow! Novice, I know.

My next challenge is to restart the game via the overlay scene. Two options I see are (1) call the primary scene brand new from the overlay and get it to start fresh or (2) send a flag to the primary scene from the overlay and have the primary scene clear and restart all physics objects that are in action. I’ve tried both approaches and haven’t yet been successful.

Any suggestions on the best approach? Thanks in advance. [import]uid: 70259 topic_id: 28620 reply_id: 115737[/import]

I found option 1 (above) to work. I can restart the game. From the overlay screen, I just call

storyboard.purgeScene(“sceneOne”)
storyboard.gotoScene(“sceneOne”)

It seems to work both from the createScene and the enterScene functions. I kept it in the enterScene portion.

Is it really that easy? Am I overlooking something? Thanks. [import]uid: 70259 topic_id: 28620 reply_id: 115873[/import]