Python: #2 pygame module making the game loop
In last article we made the game display in pygame but the the display was disappearing to solve that we will make the game in this article so that the display will not disappear.
Those who has not read mine last article they can read – https://knowledge-junction.in/2022/07/22/python-1-introduction-to-pygame-module/ so that you will understand better in this article
But before creating the game loop we will give the title to our display
import pygame initilize_pygame_module = pygame.init() ''' First we are storing pygame.display.set_mode((900,600)) in a variable because to make the game on the display we will be using this variable ''' game_display = pygame.display.set_mode((900,600)) #Giving the title to our display # pygame.display.set_caption allow us to set the title to our display title = pygame.display.set_caption("My first Python game")
Now title will be seen after updating but not able to take the screenshot because the screen is disappearing very fast so lets create the game loop
import pygame initilize_pygame_module = pygame.init() game_display = pygame.display.set_mode((900,600)) title = pygame.display.set_caption("My first Python game") # Before creating the loop we will make some specific variabl exit_game = False ''' We have created this variable because when the user will exit the game this exit_game will become true''' # Creating the variable when the game will be over game_over = False # Creating the loop while not exit_game: pass # This explains that the display will not disappear till the game_exit becomes True # Pass statement is given so the error should not occur till we do not complete the whole loop
Now the screen will not disappear. Let’s see.
But the problem is when you try to close this window the window will not response because we have created the infinite loop to close we need to stop program or delete the terminal.
We will handle this event and complete the loop in next article. So be with our series.
Thanks for reading📖
Have a nice day!