我想用 pygame 在 python 中创建简单的游戏。有一些按钮,但有时它不响应。我想要低帧率,因为它的游戏简单,但我也想让按钮像往常一样等待点击。有可能吗?
就像我不点击那 60/1000 毫秒它不起作用,对吗?如果我是,那么还有其他可能以 60 fps 运行游戏并像往常一样等待输入吗?
使用它来捕捉点击:
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)