I am having a weird display when I run a simple Pygame. The game runs perfectly but the screen is weird.
Here's the code:
import pygame
pygame.init()
window = pygame.display.set_mode((500, 500))
pygame.display.set_caption('First Game')
pygame.display.update()
x = 50
y = 50
width = 40
height = 60
vel = 5
run = True
while run:
pygame.time.delay(100)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.draw.rect(window, (255, 0, 0), (x, y, width, height))
pygame.quit()
You need to update the screen every frame. Put pygame.display.update()
inside your main_loop
, and remove it from original positon:
while run:
pygame.time.delay(100)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.draw.rect(window, (255, 0, 0), (x, y, width, height))
pygame.display.update()
This should work
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.