Game play logic

Thanks to Rob Miracle’s answer to my previous post I now have a few more questions.

Assumption: I assume that I can only call scene:create once?  Sounds logical - create. :slight_smile:

I had used scene:create to show the images of the game but I think I will have to change that since I now need to some pre-prep work and show other stuff first.

What I will need to do is show some text saying - what they need to do then show the background.

QUESTION 1:  I assume I don’t need to “clear the screen” here as the image will overlay anything I wrote before.

Then after they win the first level - I will write some words on the screen with display.newText.  Then let them begin next level.

QUESTION 2: I assume I should “clear the screen” instead of loading image again, right?  So, what is the best way to “clear the screen” but leave the image that I loaded previously intact?  Or should I clear the whole screen (if so, how) then reload the image?

Thanks!

If you want to clear the screen there is no way around it - you just have to go and remove all the parent groups of everything on the screen. You don’t need to remove every object individually but you do have to be careful about getting rid of Runtime listeners because they will hold onto objects.

You should do this in the did phase of the hide event.

Common logic when showing an end of level result and then navigating to a new level is to have a dialog scene shown over the top and then to navigate to an intermediate scene, if you intend to reuse the current scene. This is because navigating to the current scene would have no effect.

horacebury, thank you. Do you know of any example code that shows this? I think seeing it in action would help me understand what is going on? Thank you!

You should have a play with some clean, new code. Just try to implement what I’ve described.

Start with a new folder and completely new .lua files. Not sure how to describe “start fresh”…

You want a scene module for the level, the overlay (end of level display) and the intermediate.

A ‘module’ is just a .lua file. A scene is everything you see in the scene template file. A scene shows everything on the screen and you only have one on screen at a time. The only exception to that is when you have an ‘overlay’ scene which is displayed on top of the current scene - and you can only have one overlay scene at a time.

What I would do is take the scene template, copy it 3 or 4 times for these scenes and put a label into each one so you can see in the simulator which scene is on screen. This is how I lay out my app navigation when I need to think about it clearly.

Copy the code in the scene template**** and save it as ‘menu.lua’, ‘level1.lua’ and ‘level2.lua’. The create a ‘main.lua’ and use it to ‘gotoScene(“menu”)’. This is how you load your menu onto the screen. You then need to put something into the ‘create’ function of each scene to make the unique. I put a piece of text with the scene’s name, but you can just use a circle with a different colour or anything.

http://docs.coronalabs.com/daily/api/library/composer/index.html#scene-template

I am sorry but I am a newbie and many of the expressions you were mentioning went over my head. I am really going to need to see an example to fully understand what you said. Sorry for my noobness.

Have you tried using the composer scene system with your “hello world” code - just changing the text “hello world1” “hello world2” per scene template to give you  a very simple example to learn from.

What horacebury means by some clean new code - i think is to get really simple so using the classic simple “hello world” may be of some help.

T.

See my edited post above for a description of the things I talked about.

If you would like a basic setup of what I described I can provide that, but it is a very, very valuable learning curve to do it yourself.

Oh, I am sorry Maybe I didn’t explain myself correctly.

First, thank you for the detail of what you said.

Yes, I have learned how to call different scenes.  My question is reusing (maybe I am not using the right word here) the same scene.

Ie I am at Play.lua - when I get done playing, I want to start over in Play.lua without getting out of Play.lua.  I need to clean the screen and let them start again.

Only when they FAIL do I let them go back to calling scene.

Go to a blank scene called loading.lua, and in loading.lua purge ‘play’ and then goto the play.lua scene again.

Correct. I think this could be improved in the Composer API, but it is logically correct. There is no logical point using ‘goto’ to from one ‘scene1’ to ‘scene1’ - it does not make sense, so there is no support for it. Using an in-between scene is the answer.

Having said that, it would be good if scene objects could be created dynamically - without being tied to the name of a .lua file - so that scenes could be loaded and populated from a single code file, but be effectively named with any name.

We just posted a tutorial with a sample complete game template.   It’s got a full composer based set of Lua files you can use to start building your game:

https://coronalabs.com/blog/2015/04/14/tutorial-the-basic-game-template/

Rob

If you want to clear the screen there is no way around it - you just have to go and remove all the parent groups of everything on the screen. You don’t need to remove every object individually but you do have to be careful about getting rid of Runtime listeners because they will hold onto objects.

You should do this in the did phase of the hide event.

Common logic when showing an end of level result and then navigating to a new level is to have a dialog scene shown over the top and then to navigate to an intermediate scene, if you intend to reuse the current scene. This is because navigating to the current scene would have no effect.

horacebury, thank you. Do you know of any example code that shows this? I think seeing it in action would help me understand what is going on? Thank you!

You should have a play with some clean, new code. Just try to implement what I’ve described.

Start with a new folder and completely new .lua files. Not sure how to describe “start fresh”…

You want a scene module for the level, the overlay (end of level display) and the intermediate.

A ‘module’ is just a .lua file. A scene is everything you see in the scene template file. A scene shows everything on the screen and you only have one on screen at a time. The only exception to that is when you have an ‘overlay’ scene which is displayed on top of the current scene - and you can only have one overlay scene at a time.

What I would do is take the scene template, copy it 3 or 4 times for these scenes and put a label into each one so you can see in the simulator which scene is on screen. This is how I lay out my app navigation when I need to think about it clearly.

Copy the code in the scene template**** and save it as ‘menu.lua’, ‘level1.lua’ and ‘level2.lua’. The create a ‘main.lua’ and use it to ‘gotoScene(“menu”)’. This is how you load your menu onto the screen. You then need to put something into the ‘create’ function of each scene to make the unique. I put a piece of text with the scene’s name, but you can just use a circle with a different colour or anything.

http://docs.coronalabs.com/daily/api/library/composer/index.html#scene-template

I am sorry but I am a newbie and many of the expressions you were mentioning went over my head. I am really going to need to see an example to fully understand what you said. Sorry for my noobness.

Have you tried using the composer scene system with your “hello world” code - just changing the text “hello world1” “hello world2” per scene template to give you  a very simple example to learn from.

What horacebury means by some clean new code - i think is to get really simple so using the classic simple “hello world” may be of some help.

T.

See my edited post above for a description of the things I talked about.

If you would like a basic setup of what I described I can provide that, but it is a very, very valuable learning curve to do it yourself.

Oh, I am sorry Maybe I didn’t explain myself correctly.

First, thank you for the detail of what you said.

Yes, I have learned how to call different scenes.  My question is reusing (maybe I am not using the right word here) the same scene.

Ie I am at Play.lua - when I get done playing, I want to start over in Play.lua without getting out of Play.lua.  I need to clean the screen and let them start again.

Only when they FAIL do I let them go back to calling scene.

Go to a blank scene called loading.lua, and in loading.lua purge ‘play’ and then goto the play.lua scene again.

Correct. I think this could be improved in the Composer API, but it is logically correct. There is no logical point using ‘goto’ to from one ‘scene1’ to ‘scene1’ - it does not make sense, so there is no support for it. Using an in-between scene is the answer.

Having said that, it would be good if scene objects could be created dynamically - without being tied to the name of a .lua file - so that scenes could be loaded and populated from a single code file, but be effectively named with any name.