Pygame Lagging真的很糟糕?

时间:2017-11-24 01:54:38

标签: python pygame

之前出现过这个问题,我并没有真正采取任何措施。所以基本上我有一个简单的程序,但它落后很多。这不是我的电脑,因为我的其他pygame程序运行正常。无论如何,请告诉我我再次做错了什么。这是代码:

import pygame

pygame.init()

white = (255,255,255)
black = (0,0,0)

window_width = 800
window_height = 600

gameDisplay = pygame.display.set_mode((800,600))
clock = pygame.time.Clock()


def gameLoop():

    characterx = 500
    characterx_change = 0

    charactery = 500
    charactery_change = 0

    while True:
        characterimg = pygame.image.load('Character.png')

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
               False
            if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                characterx_change += -20
                charactery_change += 0
            if event.key == pygame.K_RIGHT:
                characterx_change += 20
                charactery_change += 0
            if event.key == pygame.K_UP:
                charactery_change += -20
                characterx_change += 0
            if event.key == pygame.K_DOWN:
                charactery_change += 20
                characterx_change += 0

        characterx += characterx_change
        charactery += charactery_change

        gameDisplay.fill(white)           
        gameDisplay.blit(characterimg, (characterx,charactery))
        pygame.display.update()
        clock.tick(15)

gameLoop()
pygame.quit()
quit()

0 个答案:

没有答案