首页 > 解决方案 > 在pygame中按下鼠标时制作精灵更改图像

问题描述

当鼠标按下一会儿时,如何让精灵改变它的图像,然后在pygame中恢复正常?我尝试制作一个尝试在短时间内更改图像的命中功能。

这是该功能:

def hit(self, hit_img):
    self.image = hit_img
    for i in range(300):
        self.update()

这是调用者:

if pygame.mouse.get_pressed():
    if weapon == "axe.png":
        weapon.hit("axe_hit.png")

这是Weapon 类的eq函数:

def __eq__(self, other):
    return True if self.image == other else False

但这没有用。我能做些什么呢?

编辑:所以将 [两个下划线]eq[两个下划线] 变成了eq

标签: pygamepython-3.8

解决方案


推荐阅读