Pause Button

I created a pause button and when I press it, it pauses the game. When the pause button is pressed I want 3 buttons to come up, “Restart”, “Go To Menu” and “Continue”. What is the best way to create the 3 buttons and make them show up? [import]uid: 82872 topic_id: 28922 reply_id: 328922[/import]

You can either create a separate module (Lua file) which encompasses your pause menu, and load/unload it via Storyboard or Director… Or you can just create this menu as a separate display group, and toggle its visibility on or off as needed. I recommend the first method, so it’s not hanging around in memory when you’re not displaying it.

Study the docs on Storyboard and Director about how to proceed. The actual buttons and menu will be typical images or rectangles with tap listeners on them (don’t forget to remove the listeners when you exit the scene!)

Brent
[import]uid: 9747 topic_id: 28922 reply_id: 116466[/import]

I looked around on the docs and figured out a way to pause the game and use alerts. Now when I pause the game, 3 options come up, “Resume”, “Restart” and “Menu”. I got resume to work, but I dont understand how to restart a level. On the forums many people have a ResetLevel.lua file that they call, can you explain how that works? What is the most efficient way to restart a level? Thank You. [import]uid: 82872 topic_id: 28922 reply_id: 116592[/import]

@BWernsman the way I restart a level is like this example

local function restart () director:changeScene("game") end button:addEventListener(touch, restart)
So basically “game” represents the lua file for game or whatever you name that file to play a game. When doing that would just basically reset everything you was doing in the game.

Does this help? [import]uid: 17058 topic_id: 28922 reply_id: 116601[/import]

I dont understand how you implement your code above into the alert. I posted my code below, Thank You so much for your help!

[code]

local function onClick(e)
if e.action == “clicked” then

–Resume
if e.index == 1 then

physics.start()
paused = false

–Restart
elseif e.index == 2 then

–Menu
elseif e.index == 3 then

end
end
end

function pauseBtn:tap(e)
local alert = native.showAlert(“Physball”, “Pause Menu”, {“Resume”, “Restart”, “Menu”}, onClick)

end

– Alert Button Listener

pauseBtn:addEventListener(“tap”, PauseBtn)
[import]uid: 82872 topic_id: 28922 reply_id: 116603[/import]

@BWernsman that would be simple it would look like this

local function onClick(e)  
 if e.action == "clicked" then  
  
  
 --Resume  
 if e.index == 1 then  
  
 physics.start()  
 paused = false  
  
 --Restart  
 elseif e.index == 2 then  
 director:changeScne("game")  
   
  
 --Menu   
 elseif e.index == 3 then  
  
  
 end  
 end  
end  
   
   
   
function pauseBtn:tap(e)  
 local alert = native.showAlert("Physball", "Pause Menu", {"Resume", "Restart", "Menu"}, onClick)  
  
end  
   
-- Alert Button Listener  
  
pauseBtn:addEventListener("tap", PauseBtn)  

That would be it… Just remember when you are restarting you have to remove Listeners, and functions, actions etc… By doing that would make the restart work.

Do you understand? [import]uid: 17058 topic_id: 28922 reply_id: 116608[/import]