小编Ale*_*len的帖子

Pygame应用程序在Mac上的运行速度比在PC上慢

我和一个朋友正在使用Pygame模块使用Python(2.7)进行游戏。到目前为止,我基本上已经完成了游戏的美术工作,而他基本上已经完成了编码工作,但是最终,我计划在完成大部分美术工作后帮助他进行编码。我在Mac(OS X的最新版本)上,我的朋友正在使用PC。

他一直在自己的PC上构建和运行游戏,截至目前,它已按计划在PC上正常工作(每秒60帧)。但是,每当我从GitHub提取代码(我的代码肯定是最新版本)并尝试运行该游戏时,该游戏的运行速度就快一半。

我们尝试将代码中的fps倍增至120,然后在PC上以两倍的速度运行,但是当我在Mac上拉出该代码时,好像仍然限制在30fps左右。

在其他任何地方,我们都没有真正找到任何令人信服的答案,但是我们对Pygame和Python来说都是新手,因此我们可能会遗漏一些非常明显的东西。

import pygame as pg
import os

os.environ['SDL_VIDEO_CENTERED'] = '1'

class Wombat:
    def __init__(self, screen_rect, image, starting_loc):
        self.screen_rect = screen_rect
        self.image = image
        self.width = 192
        self.height = 96
        self.starting_loc = starting_loc
        self.rect = self.image.get_rect(bottomleft=starting_loc)
        self.speed = 5
        self.grav = .5

        self.jumping = False
        self.y_vel = 0

    def update(self):
        self.rect.clamp_ip(self.screen_rect)
        self.jump_update()

    def render(self, screen):
        screen.blit(self.image, self.rect)

    def move(self, x, y):
        self.rect.x += x * self.speed
        self.rect.y += y * self.speed

    def jump_update(self):
        if self.jumping:
            self.y_vel += …
Run Code Online (Sandbox Code Playgroud)

python pygame python-2.7

2
推荐指数
1
解决办法
2345
查看次数

标签 统计

pygame ×1

python ×1

python-2.7 ×1