您如何解决此问题;TypeError:参数1必须是pygame.Surface,而不是SpriteSheet;?

您如何解决此问题;TypeError:参数1必须是pygame.Surface,而不是SpriteSheet;?,pygame,python-3.7,Pygame,Python 3.7,我正在做一个平板游戏。我有一个等级课程作为蓝图,我把它传递到等级1和等级2。然而,我不断地收到一个错误:“TypeError:参数1必须是pygame.Surface,而不是SpriteSheet”(底部的完整错误) 有人知道如何解决这个问题吗?注意:错误在底部 class Level(object): def __init__(self, player): """ Constructor. Pass in a handle to player. Needed for

我正在做一个平板游戏。我有一个等级课程作为蓝图,我把它传递到等级1和等级2。然而,我不断地收到一个错误:“TypeError:参数1必须是pygame.Surface,而不是SpriteSheet”(底部的完整错误) 有人知道如何解决这个问题吗?注意:错误在底部

class Level(object):

        def __init__(self, player):
    """ Constructor. Pass in a handle to player. Needed for when moving platforms
        collide with the player. """

    # Lists of sprites used in all levels. Add or remove
    # lists as needed for your game.
    self.platform_list = None
    self.enemy_list = None

    # Background image
    self.background = None

    # How far this world has been scrolled left/right
    self.world_shift = 0
    self.level_limit = -1000
    self.platform_list = pygame.sprite.Group()
    self.enemy_list = pygame.sprite.Group()
    self.player = player

    # Update everything on this level
    def update(self):
        """ Update everything in this level."""
        self.platform_list.update()
        self.enemy_list.update()

    def draw(self, screen):
        """ Draw everything on this level. """

        # Draw the background
        # We don't shift the background as much as the 
    sprites are shifted
        # to give a feeling of depth.
        screen.blit(self.background, (self.world_shift 
        // 3, 0))

        # Draw all the sprite lists that we have
        self.platform_list.draw(screen)
        self.enemy_list.draw(screen)


# Create platforms for the level
class Level01(Level):
    """ Definition for level 1. """

    def __init__(self, player):
        """ Create level 1. """

        # Call the parent constructor
        Level.__init__(self, player)

        self.background = 
        SpriteSheet('background_01.png')

        self.background.sprite_sheet.set_colorkey(constants.WHITE)
        self.level_limit = -2500


# Create platforms for the level
class Level02(Level):
    """ Definition for level 2. """

    def __init__(self, player):
        """ Create level 1. """

        # Call the parent constructor
        Level.__init__(self, player)

        self.background = SpriteSheet('background_02.png')

        self.background.sprite_sheet.set_colorkey(constants.WHITE)
        self.level_limit = -1000


Traceback (most recent call last):
  File 
"/Users/qingduliu/PycharmProjects/Platformer/platform_scroller.py", 
line 107, in <module>
    main()
  File 
"/Users/qingduliu/PycharmProjects/Platformer/platform_scroller.py", 
line 90, in main
    current_level.draw(screen)
  File "/Users/qingduliu/PycharmProjects/Platformer/levels.py", 
line 43, in draw
    screen.blit(self.background, (self.world_shift // 3, 0))
TypeError: argument 1 must be pygame.Surface, not SpriteSheet
类级别(对象):
定义初始(自我,玩家):
“”“构造函数。将句柄传递给播放器。移动平台时需要
与播放器碰撞。”“”
#所有级别中使用的精灵列表。添加或删除
#列出游戏所需的列表。
self.platform\u list=无
self.敌军_列表=无
#背景图像
self.background=None
#这个世界向左/向右滚动了多远
self.world\u shift=0
self.level_limit=-1000
self.platform_list=pygame.sprite.Group()
self.敌军_list=pygame.sprite.Group()
self.player=玩家
#更新此级别上的所有内容
def更新(自我):
“”“更新此级别中的所有内容。”“”
self.platform_list.update()
self.defence_list.update()
def提取(自身,屏幕):
“”“在此级别上绘制所有内容。”“”
#画背景
#我们不会像改变背景那样改变背景
精灵移动了
#给人一种深度的感觉。
screen.blit(self.background,(self.world\u shift
// 3, 0))
#画出我们所有的精灵列表
自我平台列表绘制(屏幕)
自身敌人列表绘制(屏幕)
#为该级别创建平台
级别01(级别):
“”“级别1的定义。”“”
定义初始(自我,玩家):
“”“创建级别1。”“”
#调用父构造函数
级别。初始(自我,玩家)
self.background=
精灵表('background_01.png')
self.background.sprite\u sheet.set\u colorkey(常量.白色)
自我水平限制=-2500
#为该级别创建平台
二级(二级):
“”“级别2的定义。”“”
定义初始(自我,玩家):
“”“创建级别1。”“”
#调用父构造函数
级别。初始(自我,玩家)
self.background=SpriteSheet('background_02.png'))
self.background.sprite\u sheet.set\u colorkey(常量.白色)
self.level_limit=-1000
回溯(最近一次呼叫最后一次):
文件
“/Users/qingduliu/PycharmProjects/Platformer/platform_scroller.py”,
第107行,在
main()
文件
“/Users/qingduliu/PycharmProjects/Platformer/platform_scroller.py”,
第90行,总机
当前水平图(屏幕)
文件“/Users/qingduliu/PycharmProjects/Platformer/levels.py”,
第43行,绘制中
screen.blit(self.background,(self.world\u shift//3,0))
TypeError:参数1必须是pygame.Surface,而不是SpriteSheet

您只能将曲面拼接到其他曲面<代码>背景不是曲面。您的代码意味着您可以使用
self.background.sprite\u sheet
访问其关联的表面,因此请尝试更改此行:

screen.blit(self.background,(self.world\u shift//3,0))
为此:

screen.blit(self.background.sprite\u sheet,(self.world\u shift//3,0))