我目前正在使用Pygame编写游戏,一旦我实现了主菜单,我的游戏的FPS被除以2,什么可能导致这种滞后? (我在谈论播放时的帧速率,当主菜单不可见时)
主菜单有代码(点列表是多边形显示当前选择的点列表):
import sys,os
import pygame
from Hud_implem import *
class MainMenu(object):
def main(self,screen):
self.buttonlist = [[0]]
self.buttonlist.append(self.pointlist((58.104,32.148),(69.396,23.915),(69.369,30.296),(58.104,38.630)))
self.buttonlist.append(self.pointlist((58.104,41.407),(77.229,27.296),(77.229,33.777),(58.104,47.888)))
self.buttonlist.append(self.pointlist((58.104,50.037),(74.187,38.185),(74.189,44.666),(58.104,56.519)))
self.buttonlist.append(self.pointlist((58.104,58.704),(66.396,52.593),(66.396,59.074),(58.104,65.185)))
clock = pygame.time.Clock()
screen_image = pygame.image.load(os.path.join("Images","Title Screen.png")).convert_alpha()
screen_image.set_colorkey((193,56,57))
screen_image = pygame.transform.smoothscale(screen_image,(SCREEN_W,SCREEN_H))
selection_layer = pygame.Surface((SCREEN_W,SCREEN_H))
selection_layer.fill((255,255,255))
selection_layer.set_colorkey((255,255,255))
selection_layer.set_alpha(100)
self.selectioned = 1
self.movecountdown = 0
while not started:
dt = clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
if event.type == pygame.KEYDOWN and event.key == 13:
self.get_pressed()
screen.fill((49,103,124),((0,0),screen.get_size()))
self.get_selection(selection_layer,screen,dt/1000.)
screen.blit(screen_image,(0,0))
pygame.display.flip()
def get_pressed(self):
if self.selectioned == 1 or self.selectioned == 2:
#started = True
Game().main(screen)
elif self.selectioned == 4:
pygame.quit()
def get_selection(self,layer,screen,dt):
keys_pressed = pygame.key.get_pressed()
if keys_pressed[pygame.K_UP] and not self.movecountdown:
self.selectioned += -1
self.movecountdown = 0.2 #NOT 2 DISPLACEMENT AT A TIME
if keys_pressed[pygame.K_DOWN] and not self.movecountdown:
self.selectioned += 1
self.movecountdown = 0.2 #NOT 2 DISPLACEMENT AT A TIME
if self.selectioned > 4:
self.selectioned = 1
if self.selectioned < 1:
self.selectioned = 4
self.movecountdown -= dt
if self.movecountdown < 0:
self.movecountdown = 0
layer.fill((255,255,255))
pygame.draw.polygon(layer,(0,0,0),self.buttonlist[self.selectioned])
screen.blit(layer,(0,0))
def percent(self,percx,percy):
return (float(percx/100*SCREEN_W),float(percy/100*SCREEN_H))
def pointlist(self,topleft,topright,bottomright,bottomleft):
topleft = self.percent(topleft[0],topleft[1])
topright = self.percent(topright[0],topright[1])
bottomright = self.percent(bottomright[0],bottomright[1])
bottomleft = self.percent(bottomleft[0],bottomleft[1])
return [topleft,topright,bottomright,bottomleft]
if __name__ == '__main__':
global started
started = False
pygame.init()
pygame.display.set_caption("Project Swordman","Icon.png")
pygame.display.set_icon(pygame.image.load(os.path.join("Images","Icon.png")))
SCREEN_W,SCREEN_H = 1366,768
#screen = pygame.display.set_mode((SCREEN_W, SCREEN_H),pygame.FULLSCREEN)
screen = pygame.display.set_mode((SCREEN_W, SCREEN_H))
MainMenu().main(screen)