Pygame Output : Black Background

Viewed 54

I want to view my blit() however once i add the line self.screen_dim.fill([255, 255, 255]) pygame.display.update() it overlaps

def __init__(self):       
self.width = 500
self.height = 500    
self.screen_dim = pygame.display.set_mode((self.width, self.height))
self.mole = pygame.image.load("mole.png")
self.mole_hit = pygame.image.load("mole-hit.png")



    

I am confused on how to get my pygame screen the images within that function is working however it overlaps if i added a new background color

def start(self):

    stat = True
    num_display = 1
    x_array = []
    y_array = []

    for i in self.mole_pos:
        x_array.append(i[0])
        y_array.append(i[1])
    

     while stat:
        Rand_Pos = random.randint(0, 8)
        if num_display == 1:
            self.screen_dim.blit(self.mole, (x_array[Rand_Pos], y_array[Rand_Pos]))

        for Event in pygame.event.get():
            if Event.type == pygame.QUIT:
                stat = False
            if self.mouse_clicked(mouse.get_pos(), self.mole_pos[Rand_Pos]):
                num_display = 0
                self.screen_dim.blit(self.mole_hit, (x_array[Rand_Pos], y_array[Rand_Pos]))
                continue

    pygame.display.flip()
1 Answers

This ahs nothing to to with class. It is just a matter of Indentation. You have to draw self.mole_hit in the application loop rather than the event loop:

def start(self):
    # [...]

    while stat:
        # [...]

        for Event in pygame.event.get():
            if Event.type == pygame.QUIT:
                stat = False
            
        #<--| INDENTATION
    
        if self.mouse_clicked(mouse.get_pos(), self.mole_pos[Rand_Pos]):
            num_display = 0
            self.screen_dim.blit(self.mole_hit, (x_array[Rand_Pos], y_array[Rand_Pos]))

        pygame.display.flip()
Related