0

For some reason, the PyGame blit command is not working for me. Whenever I run my code, nothing appears on screen, but there is no error message in the console.

import pygame

pygame.init()
screen = pygame.display.set_mode((1920, 1080))
clock = pygame.time.Clock()

def loadImages():
    global ground
    ground = pygame.image.load("assets/ground/tile.png")

loadImages()

# Game Loop
while True: 
    screen.blit(ground, (0, 0))
    pygame.display.update()
    clock.tick(30)
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • You have to handle the events in the application loop. See [`pygame.event.get()`](https://www.pygame.org/docs/ref/event.html#pygame.event.get) respectively [`pygame.event.pump()`](https://www.pygame.org/docs/ref/event.html#pygame.event.pump): *"For each frame of your game, you will need to make some sort of call to the event queue. This ensures your program can internally interact with the rest of the operating system."* – Rabbid76 Apr 16 '23 at 06:17

1 Answers1

0
import pygame,sys

pygame.init()
screen = pygame.display.set_mode((1920, 1080))
clock = pygame.time.Clock()

def loadImages():
    global ground
    ground = pygame.image.load("assets/ground/tile.png").convert_alpha()

loadImages()

# Game Loop
while True: 
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
    screen.blit(ground, (0, 0))
    pygame.display.update()
    clock.tick(30)

Try this

  • What is the problem with the code in the question? Can you elaborate on that? Please read [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer) – Rabbid76 Apr 16 '23 at 06:30