is "will" phase required?

I read this on the blog.

http://coronalabs.com/blog/2014/01/21/introducing-the-composer-api-plus-tutorial/

In Composer, scene:show() replaces both the willEnterScene() and enterScene() functions from Storyboard. This function will be called twice when a scene shows: once for each of these phases: “will” — called when the scene is still off screen (but is about to come on screen). “did” — called when the scene is fully on screen.

I’m just wondering if the WILL phase is mandatory? Or can I get away with not putting anything in there? Are there any 3rd party tutorials on Composer, btw? I haven’t seen anything outside of the blog post (see above) that really give one the “low-down” on Composer…

It’s not mandatory that you do anything during that phase, but it’s mandatory that you test for it or your code will execute twice.  I suspect you want something more like:

function scene:show( event )

     if event.phase == “did” then

           – do your did stuff here

     end

end

and that will ignore the “will” phase.

Rob

It’s not mandatory to do anything at all. If you do then it might be a bit dull though. 

Composer is really very simple. Each separate visually different part of your game is a scene - title page, high score table, game for example. Different levels are the same ‘scene’. You switch from scene to scene using gotoScene() - triggered by various things that might happen in a game, a time period expiring, a button being tapped. A bit like a rotating stage in a play (I have my own version of Composer, Corona’s doesn’t fit my style, it’s about 400 lines of code and about 1/3 of those are comments - there’s not a huge amount in it :slight_smile: )

Whenever you go to a new scene Corona tells you wants going on - that’s what the ‘events’ are, they are messages from Corona “I’m about to switch to this scene” (will) “I’ve just switched to this scene” (did). You can ignore them if you want - though usually you have to do something. Apart from this all Corona really does is automate the transition bits for you.

Composer is actually a thing called a “Finite State Machine” which is dedicated to scene changes. If you have a look for FSM on google there are plenty of articles (it is used in gaming for many things that have a ‘state’) that will range from the very simple to the horribly complicated. It is a worthwhile ‘design pattern’ to know outside its use in Composer. It is especially useful in AI.

(As an example, in the game ‘PacMan’ the ghosts have two ‘states’ - wandering around and running away).

They are often done doing diagrams showing the states (scenes) and how you move between them (this is one I found mimicking Ant behaviour). The ant has four states, which it shifts between as things happen. It may be worthwhile drawing a similar sort of diagram for your game before you start - instead of ‘Ant states’ you would have ‘game scenes’, and the arrows, which represent some sort of action or event in the game are scene transfers. 

ch09_fig03.jpg

Thanks for the posts. I’m still having trouble understanding how Composer works. I think Im stuck for the moment… I will have to wait for a good tutorial series to come out on Composer (hopefully someone makes one within the next couple months, I will be the first to buy…) - I have my app pretty much done I just have to get Composer going…

I dont want to use Storyboard if it is no longer going to be supported, so…Until then, I remain to have “coder’s block”…But I appreciate the attempts to help me. Thanks.  :\

Seriously, I would forget about Composer for a bit, and read up on Finite State Machines - this isn’t difficult, but it’s a bit ‘different’. 

Composer is really just a finite state machine with automatic transition displaying (and a bit of memory management), so when you’ve got the idea of how FSMs work then Composer should be much clearer.

It’s not mandatory that you do anything during that phase, but it’s mandatory that you test for it or your code will execute twice.  I suspect you want something more like:

function scene:show( event )

     if event.phase == “did” then

           – do your did stuff here

     end

end

and that will ignore the “will” phase.

Rob

It’s not mandatory to do anything at all. If you do then it might be a bit dull though. 

Composer is really very simple. Each separate visually different part of your game is a scene - title page, high score table, game for example. Different levels are the same ‘scene’. You switch from scene to scene using gotoScene() - triggered by various things that might happen in a game, a time period expiring, a button being tapped. A bit like a rotating stage in a play (I have my own version of Composer, Corona’s doesn’t fit my style, it’s about 400 lines of code and about 1/3 of those are comments - there’s not a huge amount in it :slight_smile: )

Whenever you go to a new scene Corona tells you wants going on - that’s what the ‘events’ are, they are messages from Corona “I’m about to switch to this scene” (will) “I’ve just switched to this scene” (did). You can ignore them if you want - though usually you have to do something. Apart from this all Corona really does is automate the transition bits for you.

Composer is actually a thing called a “Finite State Machine” which is dedicated to scene changes. If you have a look for FSM on google there are plenty of articles (it is used in gaming for many things that have a ‘state’) that will range from the very simple to the horribly complicated. It is a worthwhile ‘design pattern’ to know outside its use in Composer. It is especially useful in AI.

(As an example, in the game ‘PacMan’ the ghosts have two ‘states’ - wandering around and running away).

They are often done doing diagrams showing the states (scenes) and how you move between them (this is one I found mimicking Ant behaviour). The ant has four states, which it shifts between as things happen. It may be worthwhile drawing a similar sort of diagram for your game before you start - instead of ‘Ant states’ you would have ‘game scenes’, and the arrows, which represent some sort of action or event in the game are scene transfers. 

ch09_fig03.jpg

Thanks for the posts. I’m still having trouble understanding how Composer works. I think Im stuck for the moment… I will have to wait for a good tutorial series to come out on Composer (hopefully someone makes one within the next couple months, I will be the first to buy…) - I have my app pretty much done I just have to get Composer going…

I dont want to use Storyboard if it is no longer going to be supported, so…Until then, I remain to have “coder’s block”…But I appreciate the attempts to help me. Thanks.  :\

Seriously, I would forget about Composer for a bit, and read up on Finite State Machines - this isn’t difficult, but it’s a bit ‘different’. 

Composer is really just a finite state machine with automatic transition displaying (and a bit of memory management), so when you’ve got the idea of how FSMs work then Composer should be much clearer.