需要了解pygame中鼠标的坐标

问题描述 投票:0回答:1

我在pygame中有一个小问题,单击左按钮时需要知道鼠标的坐标,但是我不知道该怎么做,如果单击按钮,则想更改按钮的颜色:

pygame.draw.rect(screen, grey, (x, y, 50, 50)

它必须成为:

pygame.draw.rect(screen, blue, (x, y, 50, 50)

感谢大家。

我已经尝试过此操作,但不起作用:

if event.type == pygame.MOUSEBUTTONDOWN:
        if event.button == 1:
            if event.pos[0] > x_tastone and event.pos[0] < x_tastone + lar_tastone and event.pos[1] > 270 and event.pos[1] < 270 + alt_tastone:
                grigioChiaro = azzurro
python
1个回答
0
投票

您可以通过此行获取坐标:

mousex, mousey = pygame.mouse.get_pos()
© www.soinside.com 2019 - 2024. All rights reserved.