首页 > 解决方案 > 类型错误:参数 1 必须是 pygame.Surface,而不是元组(动画时发生)

问题描述

在尝试创建动画系统时,我遇到了这个错误:TypeError: argument 1 must be pygame.Surface,not tuple。它出现在函数 draw 的最后一行。此外,如果我尝试调用主程序中的方法,程序将运行但它会立即停止而不提供任何错误代码。

import pygame
class Animation():
def __init__(self, imageList):
    self.imageList = imageList
    self.animationTimer = 0
    self.animationSpeed = 1
    self.imageIndex = 0
def update(self):
    self.animationTimer+=1
    if self.animationTimer >= self.animationSpeed:
        self.animationTimer = 0
        self.imageIndex+=1
        if self.imageIndex >= len(self.imageList)-1:
            self.imageIndex=0
def draw(self, screen, x, y):
    screen.blit(self.imageList[self.imageIndex], (x,y))

标签: pythonpython-3.xpygame

解决方案


推荐阅读