我有一张图片:
newGameButton = pygame.image.load("images/newGameButton.png").convert_alpha()
然后,我将其显示在屏幕上:
screen.blit(newGameButton, (0,0))
如何检测鼠标是否在触摸图像?
使用Surface.get_rect获得Rect描述你的边界Surface,然后使用.collidepoint()来检查,如果鼠标光标这里面Rect。
Surface.get_rect
Rect
Surface
.collidepoint()
例:
if newGameButton.get_rect().collidepoint(pygame.mouse.get_pos()): print "mouse is over 'newGameButton'"