Python - Pygame屏幕闪烁(screen.fill)

时间:2016-02-09 21:52:51

标签: python pygame

import time
import sys
import random
import pygame

#Variables
white = (255,255,255)
simStart = True
black = (0,0,0)
red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)
x = 590.575
y = 450
clock = pygame.time.Clock()

pygame.init()

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

pygame.display.set_caption("Squirrel Problem")

screen.fill(white)

pygame.display.update()

while simStart == True:
    while x > 1:
        for event in pygame.event.get():
            if (event.type==pygame.QUIT):
                pygame.quit()

        screen.fill(white)

        pygame.draw.rect(screen, red, (300, 50, 600, 291.53))
        pygame.draw.rect(screen, blue, (x, y, 18.85, 55.81))

        x = x - .5
        clock.tick(30)
        pygame.display.update()

当我运行代码时,屏幕会闪烁。我听说这是因为screen.fill()但我不知道另一种方法来清除[pygame.draw.rect的最后位置(屏幕,蓝色,(x,y,18.85,55.81))] 。有没有人知道如何在没有屏幕故障/闪烁的情况下做到这一点?

0 个答案:

没有答案
相关问题