我已经有一段时间了,基本上这是所有相关的代码
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属性的精灵添加到组中。在
我还没有找到一个教程来解决这个问题,谢谢
你会想做
snowballs.add(self)
和英雄一样。pygame.sprite.Group.add(Sprite)
。或者,你可以说global snowballs
和global hero
相关问题 更多 >
编程相关推荐