如何将精灵添加到PyGame组

2024-10-02 10:18:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经有一段时间了,基本上这是所有相关的代码

hero=pygame.sprite.Group()
snowballs=pygame.sprite.Group()

class main_character(pygame.sprite.Sprite):
    def __init__(self,pos,*groups):
       pygame.sprite.Sprite.__init__(self,*groups)
       self.image=direction
       self.rect=self.image.get_rect(topleft=pos)
       self.add(hero)


class my_snowball(pygame.sprite.Sprite):
    def __init__(self,pos,*groups):
        pygame.sprite.Sprite.__init__(self,*groups)
        self.image=snowball
        self.rect=self.image.get_rect(topleft=pos)
        self.add(snowballs)

print(hero)
print(snowballs)

其中direction是角色图像,snowball是snowball图像。在

印刷品(英雄)和印刷品(雪球)说,在这些团体中没有任何精灵,我想知道为什么。逻辑似乎就在那里,因为我正在将具有rect属性的精灵添加到组中。在

我还没有找到一个教程来解决这个问题,谢谢


Tags: posrectimageselfinitdefgrouppygame

热门问题