python 粒子动画_python-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)

另一个选择是使该类成为一个元组,如下所示:

class classsmoke():

'classsmoke(location)'</

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值