AttributeError:"平台"对象没有属性"图像"

时间:2018-01-31 14:24:45

标签: python

我是一名自学成才的程序员,我最近一直在构建这个平台游戏。我现在已经被困住了一段时间,似乎无法解决任何更多的错误。我确实有多个文件,所以错误可能在我的代码中的其他位置,并且可能有多个。我看了好几个小时,没有想到任何事情。如果有人能帮我解决这个问题,我将不胜感激。

here is the link代码

这是当前有错误的代码的文件:

   class Levels():

   world_snap = 0

    #This is a list of sprites used within the game 
    platform_array = None

    #This is the variable for the background image
    level_background = None

    #This controls the movement of the screen with the level
    world_scroll = 0
    level_handleing = -1000

    def __init__ (self, player):

        #This code is used when a player collides with a platform 
        self.platform_array = pygame.sprite.Group()
        self.player = player


    def update_level(self):
        #This code updates the level throughout 
        self.platform_array.update()


    def output(self, screen):
        color = (255, 0, 0)

        #This code draws the background
        screen.fill(color)
        screen.blit(self.background, (self.world_scroll // 3,0))

        #This code draws the sprite lists
        self.platform_array.draw(screen)


    def snap_world(self, snap_x):

        #This code takes into account the amount of shift in the world 
        self.world_snap += snap_x

        #This shifts all of the sprite lists
        for platform in self.platform_array:
            platform.rect.x += snap_x


#Creating the first level
class level_1(Levels):

    def __init__(self, player):

        #This code calls the parent constructor so the attribute player is known
        Levels.__init__(self, player)

        background_color = (255, 255, 255)

        self.background = pygame.image.load("better_background.jpg").convert()
        self.background.set_colorkey(background_color)
        self.level_limit = -2500

        #This code puts the x and y values of the platform into the array
        level = [ [Final_Project_Platforms.grass_on_left, 500, 500],
                  [Final_Project_Platforms.grass_in_middle, 570, 500],
                  [Final_Project_Platforms.grass_on_right, 640, 500],
                  [Final_Project_Platforms.grass_on_left, 800, 400],
                  [Final_Project_Platforms.grass_in_middle, 870, 400],
                  [Final_Project_Platforms.grass_on_right, 940, 400],
                  [Final_Project_Platforms.grass_on_left, 1000, 500],
                  [Final_Project_Platforms.grass_in_middle, 1070, 500],
                  [Final_Project_Platforms.grass_on_right, 1140, 500],
                  ]

        #This code goes through the array and adds the platforms
        for platforms in level:
            tile = Final_Project_Platforms.platforms(platforms[0])
            tile.rect.x = platforms[1]
            tile.rect.y = platforms[2]
            tile.player = self.player
            self.platform_array.add(tile)

错误是:

line 38, in output self.platform_array.draw(screen) 
File "C:\Python33\lib\site-packages\pygame\sprite.py", line 475, in draw 
self.spritedict[spr] = surface_blit(spr.image, spr.rect) AttributeError: 
'platforms' object has no attribute 'image'`

我期待看到回复

谢谢你。

1 个答案:

答案 0 :(得分:0)

不清楚错误显示在哪一行,但尝试取消注释以下行:

self.image = pygame.Surface([10, 10])