简体   繁体   English

Pygame刮擦错误

[英]Pygame Blitting Error

I am relatively new in python and started coding in pygame. 我在python中相对较新,因此开始在pygame中进行编码。 For some reason, when I am rendering some images on a surface, it doesn't blit the images. 由于某些原因,当我在表面上渲染某些图像时,它不会使图像变白。 But when I minimize it and then open it again, it works fine. 但是,当我最小化它然后再次打开它时,它可以正常工作。 Is there any fix to this problem? 这个问题有解决办法吗? Thanks in adavance. 非常感谢。

Non-fullscreen error: https://youtu.be/q_2FT8OD7O4 非全屏错误: https//youtu.be/q_2FT8OD7O4

Fullscreen error: https://youtu.be/9XKnhtN5s5k 全屏错误: https : //youtu.be/9XKnhtN5s5k

My code, just in case if something's wrong in it: 我的代码,以防万一其中有问题:

import pygame

displayWidth = 1920
displayHeight = 1080

pygame.init()

gameDisplay = pygame.display.set_mode((displayWidth,displayHeight),pygame.FULLSCREEN)
pygame.display.set_caption('Road Fighters')
clock = pygame.time.Clock()

car = pygame.image.load('Car.png')
grassLeft = pygame.image.load('Grass Left.png')
grassRight = pygame.image.load('Grass Right.png')
blank = pygame.image.load('Left.png')
lining = pygame.image.load('Lining.png')
miniMap = pygame.image.load('Progress.png')
miniCar = pygame.image.load('Small Car.png')
road = pygame.image.load('Road.png')

def car(x,y):
    gameDisplay.blit(car, (x,y))

def draw():
    gameDisplay.blit(blank,(0,0))
    gameDisplay.blit(miniMap,(670,0))
    gameDisplay.blit(grassLeft,(720,0))
    gameDisplay.blit(lining,(1020,0))
    gameDisplay.blit(road,(1030,0))
    gameDisplay.blit(lining,(1610,0))
    gameDisplay.blit(grassRight,(1620,0))

def gameloop():
    while True:
        for event in pygame.event.get():
##            if event.type == 2 or event.type == 12:
##                pygame.quit()
##                quit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT: dx = -3
                elif event.key == pygame.K_RIGHT: dx = 3
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_LEFT: dx += 3
                elif event.key == pygame.K_RIGHT: dx += -3
draw()
gameloop()   

您需要在游戏循环中添加pygame.display.flip()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM