lxFirebal69xl Posted July 27, 2015 Share Posted July 27, 2015 I was wondering how would you guys go about making a pause screen while you play the game, aka, the player presses ESC and a menu shows up, completely stoping everything in the world, then I guess 2 buttons would pop up, "continue" and "exit". Each of them doing exactly what they say, obviously. Quote Link to comment Share on other sites More sharing options...
Genebris Posted July 27, 2015 Share Posted July 27, 2015 Well, I guess you have to add variable in all your scripts that will be true when the game is on pause. For example in enemy script you should check this variable each update and move enemy only if it's false. There is no automatic way to stop time for all entities and scripts. Or you can stop calling World:Update? Maybe it's a proper way. Quote Link to comment Share on other sites More sharing options...
thehankinator Posted July 27, 2015 Share Posted July 27, 2015 You could do something like this in the main loop of App.lua: In Start() self.paused = false In Loop() if self.window:KeyHit(Key.P) then self.paused = not self.paused if self.paused then Time:Pause() else Time:Resume() end end --Update the app timing Time:Update() --Update the world if self.paused then --draw your menu --if mouse clicked --if mouse is over button --do something else self.world:Update() end --Render the world self.world:Render() Basically read up on Time:Pause() and Time:Resume() Quote Link to comment Share on other sites More sharing options...
tjheldna Posted July 27, 2015 Share Posted July 27, 2015 Looking into Time::Pause and Time::Resume() would be a good place to start. Pretty sure that stops the physics simulation too. http://www.leadwerks.com/werkspace/page/api-reference/_/time/timepause-r498 Quote Link to comment Share on other sites More sharing options...
lxFirebal69xl Posted July 27, 2015 Author Share Posted July 27, 2015 Alright, thank you for your answers, I'll look into it. Quote Link to comment Share on other sites More sharing options...
holschuh Posted July 27, 2015 Share Posted July 27, 2015 Hi, you have to handle sounds(noise.lua) by yourself - souds Play and Play and Play... cu Volker Quote Link to comment Share on other sites More sharing options...
lxFirebal69xl Posted July 27, 2015 Author Share Posted July 27, 2015 Hi, you have to handle sounds(noise.lua) by yourself - souds Play and Play and Play... cu Volker Yea, I was expecting that to happen. It's more complicated than I thought it would be Quote Link to comment Share on other sites More sharing options...
holschuh Posted July 28, 2015 Share Posted July 28, 2015 Sound may to handle with an global table adding all Sound and parse it to pause them. But there so many other things not time dependent. Quote Link to comment Share on other sites More sharing options...
xtom Posted July 31, 2015 Share Posted July 31, 2015 This is my PauseMenu.lua script below that I'm using in my game - I put it on a pivot and make it a child of the player. It also has a restart map option if player is dead. Could probably be improved but it does the job and should be fairly portable. --[[ Apply this script to a pivot and make it a child of the player entity This script uses the Esc key to pause - you will need to remove the Esc key check from App.lua In App.lua - App:Start() you need to have self.exitgame = false --]] Script.restartMap="start.map"--path "Restart Map" "Map (*.map):map|Maps" function Script:Start() self.screenWidth = App.context:GetWidth() self.screenHeight = App.context:GetHeight() self.fontsize = 24 self.font = Font:Load("Fonts/arial.ttf",self.fontsize) App.context:SetFont(self.font) self.resumeTxt = "Resume" self.resumeTxtWidth = self.font:GetTextWidth(self.resumeTxt) self.resumeTxtPos = Vec2((self.screenWidth/2)-(self.resumeTxtWidth/2),(self.screenHeight/2)-60) self.restartTxt = "Restart" self.restartTxtWidth = self.font:GetTextWidth(self.restartTxt) self.restartTxtPos = Vec2((self.screenWidth/2)-(self.restartTxtWidth/2),(self.screenHeight/2)-60) self.exitTxt = "Exit" self.exitTxtWidth = self.font:GetTextWidth(self.exitTxt) self.exitTxtPos = Vec2((self.screenWidth/2)-(self.exitTxtWidth/2),self.resumeTxtPos.y+(self.fontsize*3)) self.gamePaused = 0 self.player = self.entity:GetParent() end function Script:UpdateWorld() if App.window:KeyHit(Key.Escape) then App.window:ShowMouse() self.gamePaused = 1 end while self.gamePaused >0 do -- get key presses if App.window:KeyHit(Key.Escape) then App.window:HideMouse() self.gamePaused = 0 end --Render the world App.world:Render() -- get mouse position and clicks local mousepos = App.window:GetMousePosition() local LeftMouseClick = App.window:MouseDown(Key.LButton) local RightMouseClick = App.window:MouseDown(Key.RButton) if self.player.script.health<=0 then App.context:SetBlendMode(Blend.Alpha) App.context:SetColor(0,0,0,0.7) App.context:DrawRect(0,0,self.screenWidth,self.screenHeight) App.context:SetFont(self.font) App.context:SetColor(1,1,1,1) -- check for mouseover resume if mousepos.y>=self.restartTxtPos.y and mousepos.y<=self.restartTxtPos.y+self.fontsize then if mousepos.x>=self.restartTxtPos.x and mousepos.x<=self.restartTxtPos.x+self.restartTxtWidth then App.context:SetColor(0,1,0,1) -- player leftclicks on item if LeftMouseClick==true then App.window:HideMouse() self.gamePaused = 0 changemapname=self.restartMap end end end App.context:DrawText(self.restartTxt,self.restartTxtPos.x,self.restartTxtPos.y) else App.context:SetBlendMode(Blend.Alpha) App.context:SetColor(0,0,0,0.7) App.context:DrawRect(0,0,self.screenWidth,self.screenHeight) App.context:SetFont(self.font) App.context:SetColor(1,1,1,1) -- check for mouseover resume if mousepos.y>=self.resumeTxtPos.y and mousepos.y<=self.resumeTxtPos.y+self.fontsize then if mousepos.x>=self.resumeTxtPos.x and mousepos.x<=self.resumeTxtPos.x+self.resumeTxtWidth then App.context:SetColor(0,1,0,1) -- player leftclicks on item if LeftMouseClick==true then App.window:HideMouse() self.gamePaused = 0 end end end App.context:DrawText(self.resumeTxt,self.resumeTxtPos.x,self.resumeTxtPos.y) end App.context:SetColor(1,1,1,1) -- check for mouseover exit if mousepos.y>=self.exitTxtPos.y and mousepos.y<=self.exitTxtPos.y+self.fontsize then if mousepos.x>=self.exitTxtPos.x and mousepos.x<=self.exitTxtPos.x+self.exitTxtWidth then App.context:SetColor(1,0,0,1) -- player leftclicks on item if LeftMouseClick==true then self.gamePaused = 0 App.exitgame = true end end end App.context:DrawText(self.exitTxt,self.exitTxtPos.x,self.exitTxtPos.y) if App.window:Closed() then self.gamePaused = 0 App.exitgame = true end --Refresh the screen App.context:Sync(true) end end You need to make some small changes in app.lua .. In app:start add self.exitgame = false In App:Loop() .. --If window has been closed, end the program if self.exitgame or self.window:Closed() then return false end --Handle map change if changemapname~=nil then --Clear all entities self.world:Clear() --Load the next map Time:Pause() if Map:Load(changemapname)==false then return false end Time:Resume() changemapname = nil end 1 Quote Check out my games: One More Day / Halloween Pumpkin Run Link to comment Share on other sites More sharing options...
Thirsty Panther Posted August 1, 2015 Share Posted August 1, 2015 Thanks for sharing. Quote Link to comment Share on other sites More sharing options...
TylerH Posted August 4, 2015 Share Posted August 4, 2015 I'd say the most logical approach is for your game to persist a finite state machine during runtime, that way you can handle states for menus, death, active playtime, spectating, etc. Combining that approach with the other advice offered above should lead you towards the light. Cheers, Tyler 1 Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
Josh Posted August 4, 2015 Share Posted August 4, 2015 Due to the amount of trouble people have with this and the frequency it comes up, a built-in solution is coming. 8 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
reepblue Posted August 4, 2015 Share Posted August 4, 2015 Due to the amount of trouble people have with this and the frequency it comes up, a built-in solution is coming. So, are you thinking about adding a function to the World/Time class to remove the step of disabling the world from updating in the loop if paused is set to true? Will old methods still work? Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Josh Posted August 4, 2015 Share Posted August 4, 2015 I'm talking about something else, but I don't want to say anything yet because I'm not 100% sure yet. Regarding the pausing logic, it is simple, just call a function that pauses the time, renders the menu in a loop, then when the player exits the menu resume the time and return from the function. You'll see soon. 4 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.