我有一个矩形:
PlayButton = pygame.draw.rect(screen, (0, 0, 0), pygame.Rect(324, 380, 354, 35))
并且我想让每当用户将鼠标悬停在矩形上时,将矩形的边框颜色更改为红色
# Checks if the rectangle is hovered over
if PlayButton.collidepoint(pygame.mouse.get_pos()):
print ('mouse is over newGameButton')
谢谢
答案 0 :(得分:1)
在鼠标悬停时设置状态变量:
hover = PlayButton.collidepoint(pygame.mouse.get_pos())
在设置了width
参数的位置另外绘制pygame.draw.rect()
:
例如红色边框,厚度为3
if hover:
pygame.draw.rect(screen, (255, 0, 0), pygame.Rect(324, 380, 354, 35), 3)