【发布时间】:2019-08-05 01:17:23
【问题描述】:
在鼠标事件期间使用surface.blit 时,blit 不会保留在屏幕上。
我有两张几乎一模一样的图片。标准图像已经存在于表面上,当鼠标悬停在图像上时,需要在现有图像之上放置另一个图像,当鼠标离开图像时,需要将其移除。
我当前的代码可以正常工作,但需要进行鼠标事件 - 当鼠标在图像内静止时,覆盖图像会被移除。我该如何解决这个问题?
def Execute(self):
while self.Running == True:
NewGameButton = pygame.image.load("./Assets/Interface/newgame.png").convert_alpha()
NewGameButtonHover = pygame.image.load("./Assets/Interface/newgame_hover.png").convert_alpha()
self.Display.blit(NewGameButton, (460,260))
pygame.display.flip()
for Event in pygame.event.get():
if NewGameButton.get_rect(topleft=(460,260)).collidepoint(pygame.mouse.get_pos()):
self.Display.blit(NewGameButtonHover, (460,260))
pygame.display.update()
pygame.quit()
注意:Execute() 函数是 App 类中的一个方法。
【问题讨论】:
标签: python python-3.x pygame pygame-surface