0

I need your help I want delete Rect and Surface with pygame but I don't find how I can do this.

For example : self.zoneclick_menu_bouton_jouer = pygame.Rect((108, 557), (dim_menu_bouton_jouer)) self.zoneclick_menu_bouton_options = pygame.Rect((408, 557), (dim_menu_bouton_options)) self.zoneclick_menu_bouton_quitter = pygame.Rect((708, 557), (dim_menu_bouton_quitter)) I really need your help, I hope I correctly explain my problem.

edit, there is the code in 3 part (and files), Class,Variables and main prog:

class Menu:  
def initialisation_menu(self):
    self.zoneclick_menu_bouton_jouer = pygame.Rect((108, 557), (dim_menu_bouton_jouer))
    self.zoneclick_menu_bouton_options = pygame.Rect((408, 557), (dim_menu_bouton_options))
    self.zoneclick_menu_bouton_quitter = pygame.Rect((708, 557), (dim_menu_bouton_quitter))
    channel1.play(musique_menu, loops = -1) #Musique de fond à l'infinie
    fenetre.blit(fond_menu, (0,0))
    #bouton-jouer
    global zoneclick_menu_bouton_jouer
    zoneclick_menu_bouton_jouer = pygame.Rect((108, 557), (dim_menu_bouton_jouer))
    fenetre.blit(menu_bouton_jouer, (108,557))
    #bouton-option
    global zoneclick_menu_bouton_options
    zoneclick_menu_bouton_options = pygame.Rect((408,557), (dim_menu_bouton_options))
    fenetre.blit(menu_bouton_options, (408,557))
    #bouton-option
    global zoneclick_menu_bouton_quitter
    zoneclick_menu_bouton_quitter = pygame.Rect((708, 557), (dim_menu_bouton_quitter))
    fenetre.blit(menu_bouton_quitter, (708,557))

    pygame.display.flip()
class Jeu:
  class Niveau_1:
       def initialisation_lv1(self):
           channel1.play(musique_menu, loops = -1) #Musique de fond à l'infinie
           fenetre.fill([0,0,0])
           fenetre.blit(lv1_background, (0,0))


#background
global fond_menu
fond_menu = pygame.image.load("images/menu/background.png").convert()
#bouton-jouer
menu_bouton_jouer = pygame.image.load("images/menu/bouton_jouer.jpg").convert()
dim_menu_bouton_jouer = menu_bouton_jouer.get_size()
#bouton-option
menu_bouton_options = pygame.image.load("images/menu/bouton_options.jpg").convert()
dim_menu_bouton_options = menu_bouton_options.get_size()
#bouton-quitter
menu_bouton_quitter = pygame.image.load("images/menu/bouton_quitter.jpg").convert()
dim_menu_bouton_quitter = menu_bouton_quitter.get_size()


menu = Menu()
lv1 = Jeu.Niveau_1()
#---------------------------------MAIN---------------------------------

menu.initialisation_menu()

while continuer:#boucle principal
    for event in pygame.event.get():
        if event.type == QUIT:
            continuer = 0
        if event.type == MOUSEBUTTONDOWN: 
            if event.button == 1: # 1= clique gauche
                if menu.zoneclick_menu_bouton_jouer.collidepoint(event.pos):
                    #Si il y a un clic sur la zone du bouton jouer
                    #On charge le jeu
                    channel2.play(son_jouer)
                    time.sleep(0.4)
                    lv1.initialisation_lv1()
                if menu.zoneclick_menu_bouton_options.collidepoint(event.pos):
                     #Si il y a un clic sur la zone du bouton options
                     #On ouvre le menu des parametres
                    print("")
                if menu.zoneclick_menu_bouton_quitter.collidepoint(event.pos):
                    channel2.play(son_quitter)
                    time.sleep(0.4)
                    pygame.quit()

    pygame.display.flip()

I hope that will help to solve the problem ps : Sorry for my english

LeGensBon
  • 5
  • 4
  • You should include at least an outline (but preferably a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve)) of the code that you are having problems with, then we can try to help. Typically if you want to remove an object from your display, you cover it with the background. Or you can completely reset the background, then only draw the things you want. Maybe check some of the [tutorials](https://www.pygame.org/wiki/tutorials). – import random Mar 02 '18 at 01:40
  • You can't delete a rect. You can make the program forget about it by not referring to it in the future, but you can't delete it. The closest you can get to deleting it is setting the variable to `None`. Can you please explain what you issue you are having with the existence of the Rect? – SnootierBaBoon Mar 05 '18 at 04:32

0 Answers0