class MySprite(pygame.sprite.Sprite):
group = pygame.sprite.Group()
def __init__(self):
self.image = pygame.image.load('relative/path') # load image
self.rect = self.image.get_rect() # create rect
self.rect.topleft = pygame.mouse.get_pos() # set the location
pygame.sprite.Sprite.__init__(MySprite.group) # add to group
你总是可以把一个新的组对象重新分配给你的旧组。在
your_old_group=新_group
我不完全确定,但它似乎是为了删除特定的精灵。在
只需使用
pygame.sprite.group
,如下所示:然后删除:
^{pr2}$我想,这取决于你是否认为这个“简单”:
如果您愿意,当然可以定义一个
^{pr2}$Group
的子类,它将此操作作为一个方法:相关问题 更多 >
编程相关推荐