Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么我在打印图像时会出错_Python_Image_Pygame_Blit - Fatal编程技术网

Python 为什么我在打印图像时会出错

Python 为什么我在打印图像时会出错,python,image,pygame,blit,Python,Image,Pygame,Blit,我试图在我正在做的游戏中加入一个敌人。但是当我运行这个项目时,python报告了一个“TypeError” File "C:\Users\Zee_S\OneDrive\Desktop\python projects\lil Shooter\Player\Lil Shooter.py", line 153, in draw screen.blit(ZwalkRight[self.walkcount//3] (self.x, self.y)) TypeError: 'py

我试图在我正在做的游戏中加入一个敌人。但是当我运行这个项目时,python报告了一个“TypeError”

File "C:\Users\Zee_S\OneDrive\Desktop\python projects\lil Shooter\Player\Lil Shooter.py", line 153, in draw
    screen.blit(ZwalkRight[self.walkcount//3] (self.x, self.y))
TypeError: 'pygame.Surface' object is not callable
[Finished in 1.4s]
但是我看了我的代码,它看起来很好

class Enemy(object):

    ZwalkRight = [pygame.image.load('ZR1.png'), pygame.image.load('ZR2.png'),]
    ZwalkLeft = [pygame.image.load('ZL1.png'), pygame.image.load('ZL2.png'),]
        
    def __init__(self, x, y, width, height, end):
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.end = end
        self.path = [self.x, self.end]
        self.walkcount = 0
        self.velo = 3

    def draw(self,win):
        self.move()
        if self.walkcount + 1 <= 33:
            self.walkcount = 0

        if self.velo > 0:
            screen.blit(self.ZwalkRight[self.walkcount//3] (self.x, self.y))
            walkcount += 1
        else:
            win.blit(self.ZwalkLeft[self.walkcount //3] (self.x, self.y))
            walkcount += 1
    def move(self):
        if self.velo > 0:
            if self.x +  self.velo < self.path[1]:
                self.x += self.velo
            else:
                self.velo = self.velo * -1
                self.walkcount = 0
        else:
            if self.x - self.vel > self.path[0]:
                self.x += self.velo
            else:
                self.velo = self.velo * -1
                self.walkcount = 0

是否有人可以修复或解释我为什么会出现此错误

在调用
blit
时,在结束方括号后缺少一个逗号:

screen.blit(self.ZwalkRight[self.walkcount//3](self.x,self.y))

screen.blit(self.ZwalkRight[self.walkcount//3],(self.x,self.y))

调用blitscreen时,在结束方括号后缺少一个逗号。名称是我对窗口的引用方式确定它工作正常,但行走动画将消失range@Zina:接受Rabbid76的答案,并为新问题创建一个新问题。我将逗号放回,但僵尸行走的动画显然是超出范围
def redrawGameWindow():
    screen.blit(bg, (0,-100))
    man.draw(screen)
    zombie.draw(screen)
    for bullet in bullets:
        bullet.draw(screen)
    pygame.display.update()

    
    pygame.display.update()

man = Player(300, 508, 64, 64)
zombie = Enemy(100, 508, 64, 64, 450)
bullets = []
run = True
while run:
     [...]