0

Can't quite understand why. Everything seems correctly indented within the running loop. Let me know if you can spot why the pygame window opens up and immediately closes afterwards. Checked out similar questions, can't see to understand. Maybe I' missing something obvious?

import pygame
import os

WIDTH = 610
HEIGHT = 760
WIN = pygame.display.set_mode((WIDTH,HEIGHT))
FPS = 60

BLACK = (0,0,0)
WHITE = (255,255,255)
GREEN = (0,255,0)

PLAYER = pygame.image.load(os.path.join('src', 'player.png'))


def window():
    WIN.fill(BLACK)
    WIN.blit(PLAYER)
    pygame.display.update()

def main():

    clock = pygame.time.Clock()
    running = True
    while running: #main game loop
        clock.tick(FPS)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False

        window()

    pygame.quit()

if __name__ == "__main__":
    main()
Rabbid76
  • 202,892
  • 27
  • 131
  • 174

1 Answers1

1

There is an error with the blit function. It requires two arguments. The image and the coordinates. So you need to enter the coordinates of the player.

Example: WIN.blit(PLAYER, (0, 0)) This will load the image on the top left corner of the page.

Also check if the path you are providing is correct and the image is able to load.

Entei
  • 11
  • 1