有没有可能用鼠标点击Pygame中不同的矩形按钮,得到x-y位置,并用它们作为变量生成if语句。你知道吗
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
mouse_x, mouse_y = pygame.mouse.get_pos()
.
.
.
if button_cliked_one and button_cliked_two:
print ('buttons clicked')
else:
print('something is wrong')
很难理解你想要什么,但也许你想存储以前的鼠标点击位置,以便绘制矩形?你知道吗
你所要做的就是把它们存储在一个不同的变量中。如果你想一次只点击两个位置,你就用它。或者可以使用Python列表来存储任意数量的单击位置。你知道吗
您可以使用变量
previous_button
和current_button
来记住最后两个按钮。然后你可以检查它们是否正确。你知道吗它类似于@jsbueno solution,但我使用两个变量,而不是list。 如果您想检查较长的组合,那么您可以使用列表。你知道吗
相关问题 更多 >
编程相关推荐