繁体   English   中英

在类内部使用pygame.Surface.blit

[英]Using pygame.Surface.blit inside class

我只能给班上一次电话。 我的代码是:

class fish:
    def __init__(self, x, y, image, speed):
        self.x = x
        self.y = y
        self.image = image
        self.speed = speed
    def be(self):
        screen.blit(self.image, (self.x, self.y))
        self.x -= self.speed
        if boot.x+36 > self.x and boot.x < self.x+5:
            if boot.y+34 > self.y and boot.y < self.y+5:
                boot.live -= 1
                boot.x = 100
                boot.y = 460
fishes = []
fishes.append(fish(900, 300, fish_1, 1))

当我在游戏循环的内部或外部调用“ fish”对象时( fishes.append(fish(900, 300, fish_1, 1))我得到了错误:

TypeError: 'fish' object is not callable

我的第一个猜测是您的代码中某处有一个fish变量。 将类重命名为Fish并将构造函数调用重命名为Fish(900, 300, fish_1, 1) ,应该没问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM