首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AttributeError: platforms对象没有image属性

AttributeError: platforms对象没有image属性
EN

Stack Overflow用户
提问于 2018-01-31 22:24:45
回答 1查看 697关注 0票数 0

我是一个自学成才的程序员,我最近一直在构建这个平台游戏。我已经被卡住了很长一段时间,似乎不能修复更多的错误。我确实有多个文件,所以错误可能在我的代码中的其他地方,并且可能不止一个。我已经看了几个小时了,什么也没想到。如果有人能帮我修复这个代码,我将不胜感激。

代码的here is the link

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

代码语言:javascript
复制
   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)

错误是:

代码语言:javascript
复制
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'`

我期待看到你的回复

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2018-01-31 22:42:54

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48544489

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档