Python Pygame中的大滞后
我在弗雷迪家玩了五个晚上的游戏,我所有的一切都正常运转。问题是当你按下灯按钮时有一个延迟。当你向左或向右移动时,也有一个非常轻微的延迟(在我添加灯光功能之前的版本中我没有注意到)。我感谢你的帮助 以下是我的代码的简化版本:Python Pygame中的大滞后,python,pygame,Python,Pygame,我在弗雷迪家玩了五个晚上的游戏,我所有的一切都正常运转。问题是当你按下灯按钮时有一个延迟。当你向左或向右移动时,也有一个非常轻微的延迟(在我添加灯光功能之前的版本中我没有注意到)。我感谢你的帮助 以下是我的代码的简化版本: import pygame, random pygame.init() screen = pygame.display.set_mode((0,0), pygame.FULLSCREEN, 32) pygame.display.toggle_fullscreen() clo
import pygame, random
pygame.init()
screen = pygame.display.set_mode((0,0), pygame.FULLSCREEN, 32)
pygame.display.toggle_fullscreen()
clock = pygame.time.Clock()
office_closed = pygame.image.load('images/office.png')
left_win = pygame.image.load('images/left_win.png')
right_win = pygame.image.load('images/right_win.png')
building_map = pygame.image.load('images/map.png')
building_map.convert_alpha()
camera_switch = pygame.image.load('images/camera_switch.png')
turn_left = pygame.image.load('images/turn_left.png')
turn_right = pygame.image.load('images/turn_right.png')
turn_left.convert_alpha()
turn_right.convert_alpha()
light_button = pygame.image.load('images/light_button.png')
v = 0
a = 0
position = 'door'
def door_lights(mouse_x, mouse_y, click, position):
global left_win, right_win
if position == 'left_win':
if click == (1,0,0) and (mouse_x >= 20) and (mouse_x <= 95) and (mouse_y >= 363) and (mouse_y <= 437):
left_win = pygame.image.load('images/left_win_light.png')
else:
left_win = pygame.image.load('images/left_win.png')
if position == 'right_win':
if click == (1,0,0) and (mouse_x >= 1185) and (mouse_x <= 1260) and (mouse_y >= 363) and (mouse_y <= 437):
right_win = pygame.image.load('images/right_win_light.png')
else:
right_win = pygame.image.load('images/right_win.png')
def office(mouse_x, mouse_y, click):
global position, a
if position == 'door':
if (mouse_x <= 95) and (mouse_y >= 100) and (mouse_y <= 500) and (a==0):
position = 'left_win'
if (mouse_x >= 1185) and (mouse_y >= 100) and (mouse_y <= 500) and (a==0):
position = 'right_win'
if a == 1: #IF THE MOUSE IS NOT OVER A BUTTON
if not ((mouse_x <= 95) and (mouse_y >= 100) and (mouse_y <= 500)) and not ((mouse_x >= 1185) and (mouse_y >= 100) and (mouse_y <= 500)):
a = 0 #RESET TO 0
if position == 'left_win':
if (mouse_x >= 1185) and (mouse_y >= 100) and (mouse_y <= 500) and (a==0):
position = 'door'
a = 1
if position == 'right_win':
if (mouse_x <= 95) and (mouse_y >= 100) and (mouse_y <= 500) and (a==0):
position = 'door'
a = 1
door_lights(mouse_x, mouse_y, click, position)
if position == 'door':
screen.blit(office_closed, (0,0))
screen.blit(turn_left, (20,100))
screen.blit(turn_right, (1185,100))
if position == 'left_win':
screen.blit(left_win, (0,0))
screen.blit(light_button,(20, 363))
screen.blit(turn_right, (1185,100))
if position == 'right_win':
screen.blit(right_win, (0,0))
screen.blit(light_button,(1185, 363))
screen.blit(turn_left, (20,100))
def main():
global v
while True:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
pygame.quit()
quit()
mouse_xy = pygame.mouse.get_pos()
mouse_x = mouse_xy[0]
mouse_y = mouse_xy[1]
click = pygame.mouse.get_pressed()
office(mouse_x, mouse_y, click)
pygame.display.update()
clock.tick(40)
main()
导入pygame,随机
pygame.init()
screen=pygame.display.set_模式((0,0),pygame.FULLSCREEN,32)
pygame.display.toggle_fullscreen()
clock=pygame.time.clock()
office\u closed=pygame.image.load('images/office.png')
left_-win=pygame.image.load('images/left_-win.png')
right\u-win=pygame.image.load('images/right\u-win.png')
building_map=pygame.image.load('images/map.png')
构建映射。转换α()
camera\u switch=pygame.image.load('images/camera\u switch.png')
左转=pygame.image.load('images/turn\u left.png')
turn\u right=pygame.image.load('images/turn\u right.png'))
向左拐。转换字母()
右转。转换字母()
light\u button=pygame.image.load('images/light\u button.png')
v=0
a=0
位置=‘门’
def门灯(鼠标x、鼠标y、单击、位置):
全球左赢,右赢
如果位置==“左赢”:
如果单击==(1,0,0)和(鼠标x>=20)和(鼠标x=363)和(鼠标y=1185)和(鼠标x=363)和(鼠标y=100)和(鼠标y=100)和(鼠标y=1185)和(鼠标y>=100)和(鼠标y每次单击灯光,都会加载一个图像。这需要一段时间,只需执行一次。将图像加载到字典或其他东西中,然后只需指向(例如)右击加载的图像。每次单击灯光,都会加载图像。这需要一段时间,而且只需执行一次。将图像加载到字典或其他工具中,然后将右击指向加载的图像。此外,您没有在所有曲面上使用.convert\u alpha()。此外,您也没有使用.convert\u alpha()在你所有的表面上。