Storyboard integration question.

Hi,

I’ve read and skimmed what I could find regarding Storyboard API but I can’t get my head around how to integrate it into my game.

I understand that there are two events for entering a scene and two for exiting but how should I define that which codes should be on which events?

My game has A) some stuff that runs one time like initializing the game, B) there are some event listeners that registered for touch events and touch handlers and C) Some codes that are registered to enterFrame to update game logic and a timer to update HUD.

So how should I integrate these 4 events into my game?

And should all my code be in any of these event listeners or it can be on the outside parts as well? I think we can because I’ve read that codes outside these event listeners run only once, and that’s logical, but what type of codes should it be?

I’m doing this mainly to reload and restart my game, since I do not want to store anything from gamer, can I safely not de-init and nullify and just remove the screen or I have to remove everything from scene and then nullify it?

Thanks. [import]uid: 206803 topic_id: 35395 reply_id: 335395[/import]

createScene() occurs only when the scene is created. If you load it once, leave, and then come back, createScene doesn’t fire. It will fire, however, if memory gets low or you manually purge the scene. Generally this is where you (a) draw the scene and (b) do basic setup.

willEnterScene() occurs just before you enter a scene (it’s not visible) This is where you want to start most of your event listeners and Runtime stuff.

enterScene() occurs as you enter a scene (it’s visible). There is a short but obvious delay between creatScene and enterScene. You can start some things here too, though it depends if you need the scene to be visible first.

Outside Stuff Outside of the scene is best kept for scene functions and variables related to scene setup. Anything you run outside of the scene is only run once because the only way to retrigger the code is destroy the scene and then re-enter. [import]uid: 41884 topic_id: 35395 reply_id: 140671[/import]

i only used three methods for my app. CreateScene(), enterScene() and exitScene(). All the other functions were just not necessary for me.

If you read / study the documentation about the storyboard, it will scare you and intimidate you, But it’s actually very easy. [import]uid: 119483 topic_id: 35395 reply_id: 140700[/import]

I have a question related to this as well.

I have a background scene which goes in every scene.
I have loaded it into main.lua so it starts up straight away and stays there, rather than loading it in every scene under create scene
From my point of view it saves me some copy and pasting - but from a programming point of view and memory conservation POV is this bad??
T [import]uid: 199068 topic_id: 35395 reply_id: 140701[/import]

andasturgames:

What i do is load it on every scene. I dont want any display object to be carried from scene to scene.

It will suck having to copy/paste those lines of code, but i think it’s best if each scene has their own display objects.

From a memory point of view, i doubt you’re saving any memory, If you feel like memory is low, you can always purge. [import]uid: 119483 topic_id: 35395 reply_id: 140751[/import]

Loading display objects outside of the scene is perfectly alright. The most common use for this is apps that need to use a tab bar (the horizontal row of buttons at the bottom of apps like the App Store or iTunes).

Just remember that since these objects are outside of the scene, you have to manage them yourself as they may not be accessible to you within any given scene. [import]uid: 41884 topic_id: 35395 reply_id: 140760[/import]

createScene() occurs only when the scene is created. If you load it once, leave, and then come back, createScene doesn’t fire. It will fire, however, if memory gets low or you manually purge the scene. Generally this is where you (a) draw the scene and (b) do basic setup.

willEnterScene() occurs just before you enter a scene (it’s not visible) This is where you want to start most of your event listeners and Runtime stuff.

enterScene() occurs as you enter a scene (it’s visible). There is a short but obvious delay between creatScene and enterScene. You can start some things here too, though it depends if you need the scene to be visible first.

Outside Stuff Outside of the scene is best kept for scene functions and variables related to scene setup. Anything you run outside of the scene is only run once because the only way to retrigger the code is destroy the scene and then re-enter. [import]uid: 41884 topic_id: 35395 reply_id: 140671[/import]

i only used three methods for my app. CreateScene(), enterScene() and exitScene(). All the other functions were just not necessary for me.

If you read / study the documentation about the storyboard, it will scare you and intimidate you, But it’s actually very easy. [import]uid: 119483 topic_id: 35395 reply_id: 140700[/import]

I have a question related to this as well.

I have a background scene which goes in every scene.
I have loaded it into main.lua so it starts up straight away and stays there, rather than loading it in every scene under create scene
From my point of view it saves me some copy and pasting - but from a programming point of view and memory conservation POV is this bad??
T [import]uid: 199068 topic_id: 35395 reply_id: 140701[/import]

andasturgames:

What i do is load it on every scene. I dont want any display object to be carried from scene to scene.

It will suck having to copy/paste those lines of code, but i think it’s best if each scene has their own display objects.

From a memory point of view, i doubt you’re saving any memory, If you feel like memory is low, you can always purge. [import]uid: 119483 topic_id: 35395 reply_id: 140751[/import]

Loading display objects outside of the scene is perfectly alright. The most common use for this is apps that need to use a tab bar (the horizontal row of buttons at the bottom of apps like the App Store or iTunes).

Just remember that since these objects are outside of the scene, you have to manage them yourself as they may not be accessible to you within any given scene. [import]uid: 41884 topic_id: 35395 reply_id: 140760[/import]

Thanks for the answers but would someone please answer my questions specifically that I asked in the first post of this topic?

In addition to those I have another question:

Since we are supposed to create and initialize objects and variables in createScene, then the scope of objects will be limited and other parts of code cannot see those. If I make them outside those functions, it may be against rules of Storyboard API since it will not have control over them. Tutorials that I’ve seen made everything global to solve this but we know better than that.

Thanks.

[import]uid: 206803 topic_id: 35395 reply_id: 141394[/import]

To make things easier to answewr, here are my questions in numbers:

1- Since we are supposed to create and initialize objects and variables in createScene, then the scope of objects will be limited and other parts of code cannot see those. If I make them outside those functions, it may be against rules of Storyboard API since it will not have control over them. Tutorials that I’ve seen made everything global to solve this but we know better than that.

2- If we create a certain number of objects in one scene and remove all of those objects later on in that scene, do we need to still add them to the storyboard’s scene object?

3- I have some functions that help on maintaining logic of the game, like changing waves and updating HUD, what do I have to do them when I’m integrating Storyboard API ?

4- I have some timers that run some functions on occasions, like a enterFrame event listener or a timer that infinitely calls update to my HUD function, do I have to alter them?

5- What about touch event listeners, such as touch event listener, do they have to change to get incorporated inside Storyboard?

Thanks guys. [import]uid: 206803 topic_id: 35395 reply_id: 141398[/import]

@rmckee282002,

Thanks, I’m actually using that skeleton code but as I mentioned in my numbered last post, I still can’t get my head around where some of my codes should go inside those events.

People did a great job explaining what Storyboard needs but as I mentioned, there are parts of my code that I’m not sure what I have to do.

It would be great if someone would kindly answer my numbered questions.

Thanks. [import]uid: 206803 topic_id: 35395 reply_id: 141401[/import]

Insert display objects in CreateScene, Functions in EnterScene…

http://developer.coronalabs.com/reference/index/scene-template

I believe the there are still some bugs in Storyboard so just insert your code where it says to and see what errors it spits out. Than you can work on fixing the individual problems until you have it working perfectly. Else you may post your code it will be easier for people to see what you need to put where.

ques1. Yes display objects in createScene, I believe other parts of code will see this

  • If we create a certain number of objects in one scene and remove all of those objects later on in that scene, do we need to still add them to the storyboard’s scene object? No you must display.remove and set object = nil

3- I have some functions that help on maintaining logic of the game, like changing waves and updating HUD, what do I have to do them when I’m integrating Storyboard API ? Copy/paste the functions into each individual enterScene (dont forget to removeScene). Use data storage like ICE(now GGDATA) will store values between scenes

4- I have some timers that run some functions on occasions, like a enterFrame event listener or a timer that infinitely calls update to my HUD function, do I have to alter them? No, just make sure you shut them off in exitScene

5- What about touch event listeners, such as touch event listener, do they have to change to get incorporated inside Storyboard? No
[import]uid: 75779 topic_id: 35395 reply_id: 141399[/import]

Okay edited my reply, hope that helps :slight_smile: [import]uid: 75779 topic_id: 35395 reply_id: 141404[/import]

Thanks for the answers:

  1. No they will not because it will be local to that function.

  2. I don’t want them to run at the start, so I should not put them in enterScene. I have some functions that I need to call depending on certain situations. My question is does Storyboard need to know about these?

Wish we had a thorough explanation along with a complex example about Storyboard rather than trying to learn it as it’s some kind of black magic left from ancient aliens. [import]uid: 206803 topic_id: 35395 reply_id: 141410[/import]

  1. You’re both right, sort of.
    a. Objects made in createScene are local to the scene, as you say.
    b. Objects inserted into the sceneGroup (self.view) can’t be addressed by their names but *do* exist as self.view[#] (since self.view is just a displayGroup. This scene is accessible in any of the scene functions.
    c. You can use non-index words to make this easier if you *really* need to access it:

-- inside a scene function local group = self.view group.jumptwice = display.newText(group, "hi there!")

That text object is now both group[1] and group.jumptwice.

d. You can create whatever you want inside createScene(), but it won’t be attached to anything unless you insert it into the group. This is important because if you delete a scene, go to another scene, etc. only the attached objects will behave according to the scene’s rules.

  1. Storyboard doesn’t have any real magic to it (apart from a lot of hard work). It’s basically a big displayGroup that behaves on specific timing. It otherwise obeys all of the regular laws of Lua.

a. Structure is something of a personal taste thing with code in general, let alone storyboard. Generally you’ll want to have all of your functions outside (before) the scene code. That way you can try and keep your scene code clean and just executing things.

b. You only need to use scene functions that you use. The template is great, but if you don’t need exitScene for anything you can drop that code safely, for instance. I think createScene is the only one specifically required (because you need to actually “make” the scene)

c. The key thing to remember is scope. If you call a function inside a scene, that function needs to be known at that point in the code, which means either writing the function beforehand or localizing the variable first. This is the same whether or not you use storyboard. [import]uid: 41884 topic_id: 35395 reply_id: 141414[/import]

  1. What works for me is to forward declare all my objects and functions local before the createScene, than just call them as globals whenever I need them.

3)Yes put functions in enterScene, storyBoard will not call the function until you tell it to.

@Richard good tip about putting all the functions outside the code than calling as needed, sounds better than just forward declaring [import]uid: 75779 topic_id: 35395 reply_id: 141416[/import]

Thanks richard9,

Thanks for the explanations and your thorough answers:

1- What if I do some local declaration on top of my scenes and in each scene event, i.e. createScene and whatnot, just access them and call constructor on them and in the extiScene event just nullify them with assigning nil to them, is it acceptable?

(I’ve seen this behavior in Corona’s storyboard sample that comes with the simulator) [import]uid: 206803 topic_id: 35395 reply_id: 141420[/import]