How do I add a start button?

Ok basically I made a game that starts straight when you open it but I want to add a start button which makes the game only start if I press it so how do I do this?

Try read Code Basics – Create a UI Button in Corona SDK

That isn’t relevant to what I need as it doesn’t start and stop my game.

That isn’t relevant to what I need as it doesn’t start and stop my game.

Without knowing how your game works, this is difficult to answer. The best way is to make this a separate scene, and pressing the button takes you to the game scene.

If you don’t want that, create the button and hide all your game display groups. Have a variable gameStarted and use that to trigger whether any listeners, timers etc respond and whether physics is paused if you’re using that.

That’s exactly how I want it but I just don’t know how to create a separate scene; I made my game in main.lua if that helps?

Please respond ASAP,

Thank you.

Look into the docs for Composer. That’s the best way to manage various scenes. I’d highly recommend converting your game to using composer. I don’t have time today to help in any more detail.

https://coronalabs.com/blog/2014/06/03/tutorial-understanding-the-composer-api/

It is quite simple to make a new scene just another .lua file in your project and require composer at the top. Then tell the button which game scene to go to. You would probably use something like this:

local function onPlayBtnRelease(event) if (event.phase == "ended") then composer.gotoScene(" your file name ") end end

It would probably be more helpful to you if you looked here:

https://docs.coronalabs.com/api/library/composer/index.html

Try read Code Basics – Create a UI Button in Corona SDK

That isn’t relevant to what I need as it doesn’t start and stop my game.

That isn’t relevant to what I need as it doesn’t start and stop my game.

Without knowing how your game works, this is difficult to answer. The best way is to make this a separate scene, and pressing the button takes you to the game scene.

If you don’t want that, create the button and hide all your game display groups. Have a variable gameStarted and use that to trigger whether any listeners, timers etc respond and whether physics is paused if you’re using that.

That’s exactly how I want it but I just don’t know how to create a separate scene; I made my game in main.lua if that helps?

Please respond ASAP,

Thank you.

Look into the docs for Composer. That’s the best way to manage various scenes. I’d highly recommend converting your game to using composer. I don’t have time today to help in any more detail.

https://coronalabs.com/blog/2014/06/03/tutorial-understanding-the-composer-api/

It is quite simple to make a new scene just another .lua file in your project and require composer at the top. Then tell the button which game scene to go to. You would probably use something like this:

local function onPlayBtnRelease(event) if (event.phase == "ended") then composer.gotoScene(" your file name ") end end

It would probably be more helpful to you if you looked here:

https://docs.coronalabs.com/api/library/composer/index.html