Help me create function GameOver

Hi guy

I made the my first game app.

Now I would like to make the following functions

  1. Function Game Over

  2. Function Try Again

I saw and studied the examples but I don’t understand.

There is a method for destroy all objcet?

thank you
[import]uid: 100428 topic_id: 21909 reply_id: 321909[/import]

@erasmo.marciano, this may be asking you to learn too much too fast, but you either need to learn how to use Director (there is a forum for it, its a Screen manager for Corona) or Storyboard, the official Corona screen manager.

Most games follow a similar pattern:

main.lua – does some initialization and loads menu.lua
menu.lua – provide buttons for settings, help, credits and play game. Depending on the button, you will load settings.lua, help.lua, gamecredits.lua or game.lua (or level1.lua, how ever your game is actually structured… lets call it game.lua for now)
game.lua – play your game. If you detect the game over setting, you load your game over screen, call it gameover.lua. If you have a retry situation, then load the retry.lua module. gameover.lua probably should have a button that takes you to menu.lua. retry.lua would have a button that takes you to game.lua.

Director ad Storyboard provides you very simple, typically one line API calls to load in these other lua modules and dispose of the screen you were just on.

In either case, you have a display group (group = display.newGroup()) that you insert all of your display objects into and when you change scenes, the scene manager of your choice removes the display group for you cleaning up all of those objects. Your clean up is left to timers and Runtime event listeners you may have fired up, stopping physics, etc. [import]uid: 19626 topic_id: 21909 reply_id: 87099[/import]

Thank you

I don’t have this stucture because I am experiencing the product

I have only main.lua and setting.lua

I’m usign physics, e a lot variables.

I saw how to do physics.stop but don’t how todo a destroy of the my variable

[import]uid: 100428 topic_id: 21909 reply_id: 87106[/import]

It’s not easy to help you without view your code, but:

  • Create a simple screen (you can change it later), only showing your final score (for example) and a icon of a button.

  • Add a listener to that button to call a function called (for example) restart()

  • Hide that screen (with alpha 0.0 or something like that).

  • Whenever the game is over, call to a function which will update the score of that screen and shows it (alpha 1.0 in the example). Maybe you should stop timers, score, physics, etc in this function.

  • create a function called restart () (for the button we’ve create). which will hide again the game over screen and changes all the variables needed as if the game was loaded in first time:

score = 0, time = 0, physics.start(), heroPosX = 200, heroPosY = 400, etc

And at mid term you will need to use director or storyboard. So, I strongly recommend you start using It know, when your code is supposed to be not too long. If you need to use it in the future you’ll have more issues adapting it to storyboard.

Hope it helps!

[import]uid: 77881 topic_id: 21909 reply_id: 87122[/import]

Thank you

I will try :slight_smile:
[import]uid: 100428 topic_id: 21909 reply_id: 87304[/import]