我想用pygame用python创建一个简单的游戏。有一些按钮,但有时不响应。我希望有低帧速率,因为它是简单的游戏,但我也希望有按钮等待点击像往常一样。可能吗
如果我不点击60/1000毫秒,它就不工作了,对吗?若我是,那个么是否还有其他可能以每秒60帧的速度运行游戏并像往常一样等待输入
使用此按钮捕捉单击:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
if pos[0] > 500 and pos[0] < 600 and pos[1] > 620 and pos[1] < 680:
button_hod_clicked = True
在主循环中使用此选项:
clock.tick(FPS)
结构:
def check_buttons(pos):
button_hod_clicked = False
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
if pos[0] > 500 and pos[0] < 600 and pos[1] > 620 and pos[1] < 680:
button_hod_clicked = True
return button_hod_clicked
def main():
run = True
striedanie = True
while run:
clock.tick(FPS)
pos = pygame.mouse.get_pos()
button_hod_clicked = check_buttons(pos)
if button_hod_clicked:
if striedanie == True:
player1_position, kolko_hodil = player_movement(player1_position)
striedanie = False
else:
player2_position, kolko_hodil = player_movement(player2_position)
striedanie = True
time.sleep(1)
如果事件处理程序检测到
MOUSEBUTTONUP
并调用check_buttons
函数,则只需获取鼠标位置,而不是每帧获取鼠标位置让我知道这是否有效
注意:
time.sleep
暂停整个程序,因此冻结窗口相关问题 更多 >
编程相关推荐