'Unable to blit a death screen within an if statement [duplicate]
I've been experimenting with pygame trying to make a demo for a basic game, I'm trying to display a death screen when the player's health reaches zero. The program is definitely running the death screen subroutine however, it doesn't actually blit the image unless i take it out of the elif statement and put it in the main loop. I've tried looking for an answer but haven't been able to find anyone with the same problem. Any help is appreciated.
here is the main loop:
def main():
clock = pygame.time.Clock()
running = True
alive = True
while running:
clock.tick(FPS)
keys_pressed = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if keys_pressed[pygame.K_ESCAPE]:
running = False
if alive == True:
########## MOVEMENT #################################
player.player_movement()
######################################################
if fireball.since_last < fireball.cooldown:
fireball.attack()
if fireball.since_last >= fireball.cooldown:
fireball.x = boss.x
fireball.attack()
fireball.since_last = 0
pygame.display.update()
window.draw_window()
player.draw_player()
boss.draw_sprite()
player.health_bar()
if pygame.sprite.collide_mask(fireball, player):
if player.health - 10 <= 0:
alive = False
else:
fireball.on_hit()
elif not alive:
window.draw_death()
EDIT: Here is the window.draw_death() function
def draw_death(self):
DIED_IMG = pygame.image.load(os.path.join('Assets', ('died.png')))
DIED = pygame.transform.scale(DIED_IMG, (1600, 800))
screen.blit(DIED, (0, 0))
print("Well then")
Solution 1:[1]
For completeness sake:
you forgot to update the screen after drawing the death screen:
elif not alive:
window.draw_death()
pygame.display.update()
while on the subject, you probably want to move the pygame.display.update() in your "alive" section to be in the end instead of the begining
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nullman |
