我在场景中使用游戏并加载按钮作为图像,当我尝试使用button[0].get_rect()
时,单击时收到坐标 0,0 而不是按钮的实际坐标。
我的代码如下
button = []
button.append(pygame.image.load('images/new_game.png').convert_alpha())
button_pos = (700, 100)
并在while
使用此代码检查按钮是否被点击
screen.fill(0)
screen.blit(button[0], button_pos)
if event.type == pygame.MOUSEBUTTONDOWN:
x, y = event.pos
if button[0].get_rect().collidepoint(x, y):
scene = 2
print(scene)