0

I am using pygame and I want to stop rendering images at a certain point, so I can create a main menu, a game state, and stuff like that. So I tried using booleans but that did not work.

Here is the code:

import pygame
pygame.init()
WIDTH, HEIGHT = 800, 600
win = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Lemonade Stand: Hard Mode")
clock = pygame.time.Clock()

main_menu = pygame.image.load('Art/Main Menu/main_menu.png')
play_button = pygame.image.load('Art/Main Menu/play.png')

main_menu = True

while True:
    for event in pygame.event.get():
    if event.type == pygame.QUIT:
        pygame.quit()
        exit()

    if main_menu:
        win.blit(main_menu, (0, 0))
        win.blit(play_button, (510, 150))

    pygame.display.update()
    clock.tick(60)
import random
  • 3,054
  • 1
  • 17
  • 22
  • 1
    Gonna be honest, I dont see the error here. Unless what you're asking is *how* exactly to do this, then in that case you are on the right track. Just have booleans that change depending on the state of the game, use if statements to check what sprites you need to draw. – KingTasaz Mar 28 '22 at 23:41
  • A common idiom is a [state machine](https://en.wikipedia.org/wiki/Finite-state_machine), see some [answers](https://stackoverflow.com/questions/20431501/pygame-game-over-screen) for examples on how to differentiate between states, e.g. _menu_, _game_ and _game over_. – import random Mar 29 '22 at 01:13
  • Just use `win.fill((0,0,0))` and your window is empty again. – The_spider Mar 30 '22 at 13:01

0 Answers0