Python pygame-粒子效果

Python pygame-粒子效果,python,2d,pygame,particles,Python,2d,Pygame,Particles,我正在用Pygame制作一个二维游戏。 我想在我正在制作的游戏中添加粒子效果。我想做一些事情,比如生烟、生火、生血等等。我很好奇有没有一个简单的方法可以做到这一点?我真的不知道从哪里开始。 我只需要一个基本案例,我可以在此基础上进行扩展。 请帮忙 您可能希望创建一个由矩形组成的类,该类在每次为烟雾更新时向上并随机向左或向右移动。然后你想做什么就做什么。我将尝试在下面制作一个示例代码,但我不能保证它会工作。可以为其他粒子效果创建类似的类 class classsmoke(pygame.Rect):

我正在用Pygame制作一个二维游戏。
我想在我正在制作的游戏中添加粒子效果。我想做一些事情,比如生烟、生火、生血等等。我很好奇有没有一个简单的方法可以做到这一点?我真的不知道从哪里开始。
我只需要一个基本案例,我可以在此基础上进行扩展。

请帮忙

您可能希望创建一个由矩形组成的类,该类在每次为烟雾更新时向上并随机向左或向右移动。然后你想做什么就做什么。我将尝试在下面制作一个示例代码,但我不能保证它会工作。可以为其他粒子效果创建类似的类

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)
类烟雾(pygame.Rect):
'类别烟雾(位置)'
定义初始化(自身,位置):
自宽=1
自身高度=1
自我中心=位置
def更新(自我):
self.centery-=3#您可能希望增加或减少该值
self.centerx+=random.randint(-2,2)#您可能还需要提高或降低该值
#使用此选项创建烟雾
烟雾=[]
对于范围(20)内的i:
追加(classsmoke(在此处插入位置))
#把这个放在游戏循环中的某个地方
对于吸烟的我:
i、 更新()

如果i.centery检查库中的粒子效果


当你说在这里插入位置是什么意思?@user1758231将两个位置的列表放入其中,x和y如下:
[132,45]
以x为第一位,y为第二位(
[x,y]
)PyIgnition有没有可用的代码示例?我不确定工作流程。非常感谢
class classsmoke():
    'classsmoke(location)'
    def __init__(self, location):
        self.center=location
    def update(self):
        self.center[1]-=3
        self.center[0]+=random.randint(-2, 2)

#to create smoke
smoke=[]
for i in range(20):
    smoke.append(classsmoke(insert location here))
#put inside game loop
for i in smoke:
    i.update()
    if i.centery<0:
        smoke.remove(i)
    else:
        pygame.draw.rect(screen, GREY, (i.center[0], i.center[1], 1, 1))
#to create smoke:
smoke=[]
for i in range(20):
    smoke.append(insert location here)
#put within your game loop
for i in smoke:
    i[1]-=3
    i[0]+=random.randint(-2, 2)
    if i[1]<0:
        smoke.remove(i)
    else:
        pygame.draw.rect(screen, GREY, (i[0], i[1], 1, 1))