小编典典

在Pygame中将鼠标悬停在图像上

python

我有一张图片:

newGameButton = pygame.image.load("images/newGameButton.png").convert_alpha()

然后,我将其显示在屏幕上:

screen.blit(newGameButton, (0,0))

如何检测鼠标是否在触摸图像?


阅读 377

收藏
2021-01-20

共1个答案

小编典典

使用Surface.get_rect获得Rect描述你的边界Surface,然后使用.collidepoint()来检查,如果鼠标光标这里面Rect


例:

if newGameButton.get_rect().collidepoint(pygame.mouse.get_pos()):
    print "mouse is over 'newGameButton'"
2021-01-20