A friend and I are making a game in Python (2.7) with the Pygame module. I have mostly done the art for the game so far and he has mostly done the coding but eventually I plan to help code with him once most of the art is done. I am on a Mac (latest version of OS X) and my friend is using a PC.
He has been building and running the game from his PC and as of right now it has been working as planned in his PC (perfect 60fps). However, whenever I pull the code from GitHub (I definitely have the most updated version of our code) and I try to run the game, the game runs like half as fast.
We have tried doubling the fps to 120 in the code and it then runs twice as fast on the PC but when I pull that code on my Mac it still seemed like I was capped around 30fps.
We haven't really found any convincing answers to this problem anywhere else, however we are both pretty new to Pygame and Python so we may be missing something very obvious.
import pygame as pg
import osos.environ['SDL_VIDEO_CENTERED'] = '1'class Wombat:def __init__(self, screen_rect, image, starting_loc):self.screen_rect = screen_rectself.image = imageself.width = 192self.height = 96self.starting_loc = starting_locself.rect = self.image.get_rect(bottomleft=starting_loc)self.speed = 5self.grav = .5self.jumping = Falseself.y_vel = 0def 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.speedself.rect.y += y * self.speeddef jump_update(self):if self.jumping:self.y_vel += self.gravself.rect.y += self.y_velif self.is_touching_ground():self.jumping = Falsedef is_touching_ground(self):return self.rect.y >= self.screen_rect.height - self.height - 50def jump(self):if not self.jumping:self.y_vel = -12self.jumping = Trueclass Control:def __init__(self):self.screensize = (1000,500)self.screen = pg.display.set_mode(self.screensize, pg.DOUBLEBUF)self.screen_rect = self.screen.get_rect()try:self.bg = pg.image.load("res\\bg.png")self.wb11 = pg.image.load("res\BlueWombat\BlueStay.png")self.wb1 = pg.image.load("res\BlueWombat\BlueWalk.gif").convert_alpha()self.wb2 = pg.image.load("res\GreenWombat\GreenStay.png")self.wb21 = pg.image.load("res\GreenWombat\GreenWalk.gif")except:self.bg = pg.image.load("res/bg.png")self.wb1 = pg.image.load("res/BlueWombat/BlueStay.png")self.wb11 = pg.image.load("res/BlueWombat/BlueWalk.gif")self.wb2 = pg.image.load("res/GreenWombat/GreenStay.png")self.wb21 = pg.image.load("res/GreenWombat/GreenWalk.gif")self.wb2 = pg.transform.flip(self.wb2, True, False)self.clock = pg.time.Clock()self.fps = 60self.quit = Falseself.keys = pg.key.get_pressed()self.wombat_one = Wombat(self.screen_rect, self.wb1, (0,450))self.wombat_two = Wombat(self.screen_rect, self.wb2, (1000-192,450))def run(self):while not self.quit:now = pg.time.get_ticks()self.held_keys(self.keys)self.event_loop()self.update()self.render()pg.display.update()self.clock.tick(self.fps)def event_loop(self):for event in pg.event.get():if event.type == pg.QUIT:self.quit = Trueelif event.type in (pg.KEYDOWN, pg.KEYUP):self.keys = pg.key.get_pressed()if event.type == pg.KEYDOWN:if event.key == pg.K_w:self.wombat_one.jump()if event.key == pg.K_UP:self.wombat_two.jump()def held_keys(self, keys):if keys[pg.K_a]:self.wombat_one.move(-1, 0)if keys[pg.K_d]:self.wombat_one.move(1, 0)if keys[pg.K_LEFT]:self.wombat_two.move(-1, 0)if keys[pg.K_RIGHT]:self.wombat_two.move(1, 0)def render(self):self.screen.blit(self.bg, (0,0))self.wombat_one.render(self.screen)self.wombat_two.render(self.screen)def update(self):self.wombat_one.update()self.wombat_two.update()app = Control()
app.run()