我知道这个标题听起来很像 Detect mouseover an image in Pygame 但是有一个错误。我尝试过从这个问题的两个答案,但它从来没有奏效。这里是我的代码的一部分:在Pygame中鼠标悬停
title = font3.render(('SQUASH!'), True, white)
play = font1.render(('PLAY'), True, white)
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
screen.blit((title), (400, 400))
screen.blit(play, (theposition))
if play.collide_point(pygame.mouse.get_pos()):
hi = font1.render(('hi'), True, white)
screen.blit(hi, (300, 300))
pygame.display.flip()
time.sleep(0.000000000000000000000000000000000000000000000000000000001)
pygame.display.flip()
'嗨'基本上是一个测试使用第一个答案。如果我用鼠标将鼠标悬停在按钮上,我正在尝试更改文本(粗体,下划线等)。它似乎没有工作。
+1使用time.sleep()等待的时间短于最短的时间间隔https://en.wikipedia.org/wiki/Planck_time – NWard
1.什么是问题? 2.你只想调用一个display.flip()。 3.您应该使用MOUSEMOTION事件来检测鼠标悬停。 4.你永远不会清除屏幕。 – ninMonkey
你如何清除屏幕?我已经尝试过在很多地方搜索,但我从未弄明白。那么如何检测单个(或一组)对象上的mousemotion? – JaredCubilla