播放按钮不起作用

时间:2020-06-21 15:21:17

标签: python-3.x

在我的外星人入侵游戏中,一切正常,直到我单击播放按钮。 当我单击它时,出现此错误:

    game_functions.py, line 45, in check_events
        check_play_button(stats, play_button, mouse_x, mouse_y)
    TypeError: check_play_button() missing 1 required positional argument: 'mouse_y'

以下是错误所在的game_functions部分:

def check_events(ai_settings, screen, stats, play_button, ship, bullets):
"""Respond to keypresses and mouse events."""
for event in pygame.event.get():
    if event.type == pygame.QUIT:
        sys.exit()
    elif event.type == pygame.KEYDOWN:
        check_keydown_events(event, ai_settings, screen, ship, bullets)
    elif event.type == pygame.KEYUP:
        check_keyup_events(event, ai_settings, ship)
    elif event.type == pygame.MOUSEBUTTONDOWN:
        mouse_x, mouse_y = pygame.mouse.get_pos()
        # Here is the error.
        check_play_button(stats, play_button, mouse_x, mouse_y)
        
def check_play_button(stats, play, button, mouse_x, mouse_y):
    """Start a new game when the player clicks Play."""
    if play_button.rect.collidepoint(mouse_x, mouse_y):
        stats.game_active = True

“ mouse_y”位于check_play_button中,但表示它丢失了。 我也看不到任何拼写错误,所以我不知道问题出在哪里。 如果需要更多代码,我会很乐意提供。

1 个答案:

答案 0 :(得分:1)

check_play_button的定义有5个参数

def check_play_button(stats, play, button, mouse_x, mouse_y):

但是您要发送4

check_play_button(stats, play_button, mouse_x, mouse_y)

应该像

check_play_button(stats, ???, play_button, mouse_x, mouse_y)