How to Make a Pause Menu in PyGame with Python!

preview_player
Показать описание
Pygame is the most common GUI package in Python for developing games, and while it is easy to learn and easy to use, there are a lot of functionalities that are not built-in automatically so you will want to learn to do them yourself!

One of the most important examples of this type of functionality is the pause menu. It will allow you to suspend the game state while maintaining progress and scores!

Thanks for watching! Be sure to leave a like and subscribe to the channel to stay up to date on all our great new content coming out every week!

Thank you LeMaster Tech Patreon Supporters!
Dale Topley
Philip Nunez
Рекомендации по теме
Комментарии
Автор

3:34 you can directly write "pause = not pause" very nice video keep on posting

isaac
Автор

Great video!
Jet-pack Joyride 🤘🏻
Congratulations on LeMaster Tech jr. 😀

gualdim
Автор

How does one implement a pause for features like in-game timers that use pygame.time.ticks to track elapsed time? Let's say you create Enemy class using OOP. Inside this class you define variables that track time by initializing pygame.time.ticks(). Then you use these variables to implement a timer which spawns a fireball every 5 seconds...

I was able to create a pause that stopped my game objects from updating on the game screen, but their pygame.time.ticks() based timers were still running in the background... These don't get stopped, they run infinitely when a certain class object is instantiated in my game... So when i resume the game, and run the code responsible for updating/rendering everything on the screen, it starts running the methods that have the timers and checking the time difference. Because the time elapsed during the pause was, for example, 15 seconds, it spawns my fireball immediately after i unpause... Everything that is handled by such timers gets buffered during the pause and immediately executed when the game is resumed...

I have tried storing the elapsed time inside a new variable when the game gets paused, and them overwrite the original line that is calculating elapsed time with the value stored on pause, but it does not work... because even if i can save the remaining time inside a variable, it still gets contrasted and compared against a variable using pygame.time.ticks() to calculate and this variable can never be stopped?


I don't know, any ideas?

zennihilator
visit shbcf.ru