【问题标题】:Why is my Pygame script not correctly filling the screen? [duplicate]为什么我的 Pygame 脚本没有正确填充屏幕? [复制]
【发布时间】:2021-09-04 12:49:33
【问题描述】:

我的代码在下面,当它运行时,Pygame 屏幕保持黑色并且根本没有填充正确的颜色,(87, 160, 211)

import pygame
pygame.init()

window_size = (800,600)

screen = pygame.display.set_mode((800,600))

car_image = pygame.image.load('car.png')

def display_car(x,y):
    screen.blit(car_image, (x,y))

running = True

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
            
    screen.fill((87, 160, 211))

    display_car(window_size[0]/2, window_size[1]/2)

【问题讨论】:

    标签: python python-3.x pygame


    【解决方案1】:

    您必须通过调用pygame.display.update()pygame.display.flip() 来更新显示

    running = True
    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
                
        screen.fill((87, 160, 211))
        display_car(window_size[0]/2, window_size[1]/2)
        pygame.display.flip()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多