Project1
标题:
粒子工厂到底怎么用
[打印本页]
作者:
tydhc
时间:
2010-10-21 13:53
提示:
作者被禁止或删除 内容自动屏蔽
作者:
miracl
时间:
2010-10-21 13:56
呃,我觉得,LZ应该把脚本发上来,大家才好解决吧……
作者:
匿名
时间:
2010-10-21 14:57
粒子的本质是虾米?
一堆SPRITE按照设定到处跑而已
粒子的运动规律是虾米?
设定几个属性然后让它们按照这些属性进行运动
运动的本质是虾米?
相对时间内发生的位移而已,也就是每帧UPDATE的时候改XY而已,改多少就是所谓的“速度”
作者:
tydhc
时间:
2010-10-23 14:07
提示:
作者被禁止或删除 内容自动屏蔽
作者:
orochi2k
时间:
2010-10-23 17:25
本帖最后由 orochi2k 于 2010-10-23 17:34 编辑
LS为什么要匿名嘛,给了我很大启发的,我试着自己编编看吧
tydhc 发表于 2010-10-23 14:07
因为偶是R界华丽的黑幕(大雾)
呃……不过鉴于版主说匿名不方便评分,于是偶囧一下……
可以参考偶的石器中的某段上古时期的源码
#粒子单个
class Particle
attr_accessor :bt
attr_accessor :vx #横位移分量
attr_accessor :vy #纵位移分量
attr_accessor :ax #横加速度分量
attr_accessor :ay #纵
attr_accessor :aax #加加速度- -0 呃……从前有棵高树,上面挂了很多人……
attr_accessor :aay #无聊的解析几何啊啊啊啊- -0
attr_accessor :lifetime #生命周期
def initialize
@bt = RPG::Sprite.new
@vx = 0
@vy = 0
@ax = 0
@ay = 0
@aax = 0
@aay = 0
@lifetime = 0
end
def dispose
if @bt == nil
return
end
@bt.dispose
@bt = nil
#GC.start
end
################################
def setlife(t)
@lifetime = t
end
def setv( vx = nil , vy = nil )
if vx != nil
@vx = vx
end
if vy != nil
@vy = vy
end
end
def seta( ax = nil , ay = nil)
if ax != nil
@ax = ax
end
if ay != nil
@ay = ay
end
end
###############################
def update
if @bt == nil
return
end
if @lifetime <= 0
@bt.bitmap.dispose
@bt.dispose
end
if @bt.disposed?
@bt = nil
return
end
@ax += @aax
@ay += @aay
@vx += @ax
@vy += @ay
@bt.x += @vx
@bt.y += @vy
@lifetime -= 1
@bt.update
end
##################################
end
复制代码
下面是如何将单个的粒子变成一坨华丽的粒子炮(大雾)
###########喷射1号###################################################
class Particle_Fire
def initialize(grtt,time,x,y)
@time = time
@particles = []
@grtt = grtt
@temp = 0
@x = x
@y = y
end
def update
if @temp >= @grtt
return
end
for i in @temp..(@temp + @grtt/@time)
@particles[i] = Particle.new
@particles[i].bt.x = @x
@particles[i].bt.y = @y
@particles[i].bt.z = 99999
@particles[i].bt.zoom_x = 0.4
@particles[i].bt.zoom_y = 0.4
@particles[i].bt.bitmap = RPG::Cache.picture("particles") #这个是粒子的贴图文件
@particles[i].bt.src_rect.set( 0 , 0 , 32 , 32)
@particles[i].bt.flash(Color.new(240+rand(15),100+rand(120),100+rand(120),255),20)
@particles[i].setlife(20)
@particles[i].setv((-200+rand(400)) * 0.05,(-300+rand(100)) * 0.05)
end
@temp += @grtt/@time
updatefire
end
def updatefire
for i in 0..@temp
if @particles[i].is_a?(Particle)
@particles[i].update
end
end
end
def dispose
for i in 0..@temp
if @particles[i].is_a?(Particle)
@particles[i].dispose
end
end
end
end
##############################################################################
复制代码
大致看完上面的代码,你就能写粒子系统了
剩下就是考虑在哪里插进去,以及垃圾回收之类的东西
粒子的华丽度一般和运动公式的诡异度有关(参考UPDATE那堆,如果粒子自身属性的坐标分量运动无法满足需求其实直接可以在粒子库的那坨东西里直接强制确定粒子的X,Y 从而做出正弦函数什么的东西)
这只是个教学用轻量级版本0.0
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1