增加Pygame中的FPS:Mac vs Windows

时间:2015-01-12 22:14:13

标签: python windows macos pygame frame-rate

我使用pygame和python在我的Windows笔记本电脑上生成了一个程序,其中白色条纹在黑色屏幕上垂直运行。当我在Windows笔记本电脑上增加FPS变量并运行它时,白色条纹将运行得更快。当我在Mac上使用相同的代码时,FPS不会增加超过55 FPS。例如,我可以在Windows上以500 FPS运行代码,条纹移动得更快。然后我可以在Mac上以500 FPS运行代码,但条纹仍然会以大约55 FPS的速度移动。我可以在Mac上使FPS低于55 FPS但不会更快。为什么是这样?如何在Mac上增加FPS以使白色条纹运行得更快?

import pygame, sys
import time
pygame.init()
FPS=500
clock=pygame.time.Clock()

size =(480,320)
screen = pygame.display.set_mode(size)
WHITE =(255,255,255)
BLACK =(0,0,0)
player_rect0 =pygame.Rect(-120,0,60,320)
player_rect1 =pygame.Rect(0,0,60,320)
player_rect2 =pygame.Rect(120,0,60,320)
player_rect3 =pygame.Rect(240,0,60,320)
player_rect4 =pygame.Rect(360,0,60,320)


direction = "right"
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

    screen.fill(BLACK)
    pygame.draw.rect(screen, WHITE, player_rect0)
    pygame.draw.rect(screen, WHITE, player_rect1)
    pygame.draw.rect(screen, WHITE, player_rect2)
    pygame.draw.rect(screen, WHITE, player_rect3)
    pygame.draw.rect(screen, WHITE, player_rect4)

    if direction == "right":
        player_rect0.centerx += 1
    if player_rect0.right >(-60+120):
        player_rect0 = pygame.Rect(-120,0,60,320)
###
    if direction == "right":
        player_rect1.centerx += 1
    if player_rect1.right >(60+120):
        player_rect1 = pygame.Rect(0,0,60,320)
###
    if direction == "right":
        player_rect2.centerx += 1
    if player_rect2.right >(180+120):
        player_rect2 = pygame.Rect(120,0,60,320)
###
    if direction == "right":
        player_rect3.centerx += 1
    if player_rect3.right >(300+120):
        player_rect3 = pygame.Rect(240,0,60,320)
###
    if direction == "right":
        player_rect4.centerx += 1
    if player_rect4.right >(420+120):
        player_rect4 = pygame.Rect(360,0,60,320)


    clock.tick(FPS)
    pygame.display.update()
    pygame.display.set_caption("fps: " + str(clock.get_fps()))

1 个答案:

答案 0 :(得分:0)

FPS通常根据您的CPU速度而定。计算机越慢,FPS越慢。它取决于您的计算机处理它的速度。