【发布时间】:2016-05-29 06:05:53
【问题描述】:
我为我的敌人创建了一个 pygame.sprite.group。 我可以将它们显示在屏幕上,但我不知道如何让它们全部移动? 我想让他们在平台上来回踱步(比如不断地左右踱步)。 我知道如何处理一个精灵的动作,但不知道如何处理一组精灵的动作。
这是我现在拥有的:
class Platform(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load('levoneplatform.png')
self.rect = self.image.get_rect()
class Enemy(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load('enemy.png')
self.rect = self.image.get_rect()
class LevOne():
def __init__(self):
self.background_image = pygame.image.load('night.png').convert_alpha()
platforms_one = [ (200,300),
(50,500),
(550,650),
(300,200),
(120,100)
]
for k,v in platforms_one:
platform = Platform()
enemy = Enemy()
platform.rect.x = k
enemy.rect.x = k
platform.rect.y = v
enemy.rect.y = v - 44
platform_list.add(platform)
enemy_list.add(enemy)
def update(self):
screen.blit(self.background_image, [0, 0])
screen = pygame.display.set_mode((800,600))
enemy_list = pygame.sprite.Group()
platform_list = pygame.sprite.Group()
其余的基本上就像我的状态变化和更新。 我不知道如何移动整个精灵组。我知道如何移动一个精灵,但不是一个列表中的一堆精灵。
【问题讨论】: