您可能只想制作一个由矩形构成的类,每次更新烟熏时,它们都会向上和向左或向左随机移动.然后在需要时将它们制成大量.我将在下面尝试创建一个示例代码,但是我无法保证它会起作用.您可以为其他粒子效果创建类似的类.
class classsmoke(pygame.Rect):
'classsmoke(location)'
def __init__(self, location):
self.width=1
self.height=1
self.center=location
def update(self):
self.centery-=3#You might want to increase or decrease this
self.centerx+=random.randint(-2, 2)#You might want to raise or lower this as well
#use this to create smoke
smoke=[]
for i in range(20):
smoke.append(classsmoke(insert location here))
#put this somewhere within your game loop
for i in smoke:
i.update()
if i.centery<0:
smoke.remove(i)
else:
pygame.draw.rect(screen, GREY, i)
另一个选择是使该类成为一个元组,如下所示:
class classsmoke():
'classsmoke(location)'</