我正在尝试在屏幕上随机产生的能量。我也希望它们在不同的时间间隔产卵,并在一段时间后消失。但是,我不知道我该怎么做。我应该使用Pygame内置的计时器函数还是有更好的方法来实现这一点?在
到目前为止,我得到的是:
class PowerUp(Image):
def __init__(self, screen_size, width, height, filename, powerup_group, color = (255, 0, 0)):
self.powerup_group = powerup_group
super().__init__(screen_size, width, height, filename, color = (255, 0 , 0))
_centerx = random.randint(20, 1100) # <-- local variable _centerx
_centery = random.randint(20, 700) # <-- local variable _centery =
self.radius = 10
self.rect = pygame.Rect(_centerx-self.radius,
_centery-self.radius,
self.radius*2, self.radius*2)
def update(self):
#Should I use pygame's timer or is there a better method?
self.powerup_group.add(PowerUp(screen_size, width, height, filename, powerup_group, color = (255, 0 , 0)))
目前没有回答
相关问题 更多 >
编程相关推荐