Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Particles alpha decay — Gideros Forum

Particles alpha decay

rrraptorrrraptor Member
edited December 2019 in General questions
I wonder, how to calculate alpha decay for particles to make them lose alpha over time... When life time = 0, alpha = 1, when life time = ttl, alpha = 0 (or wise versa).
From wiki:
factor applied to speedX and speedY, speedAngular, speedGrowth and alpha at the beginning of each frame
So I did a quick test:
local frames = 0 -- frames counter
local ttl = 100 -- how many frames particle will be alive
local alpha = 1 -- initial alpha
local decay = 0.955-- magic number
local obj = Pixel.new(0, alpha, 100,100) -- fake "particle"
stage:addChild(obj)
 
local realParticles = Particles.new() 
stage:addChild(realParticles)
realParticles:addParticles{{
	ttl = ttl, 
	decayAlpha = decay, 
	alpha = alpha, 
 
	x = 150, y = 50, 
	size = 100, 
	color = 0, 
}}
function update()
	frames += 1
	if (frames > ttl) then 
		print("Fake alpha:", alpha)
 
		local _,a=realParticles:getParticleColor(1)
		print("Real alpha:", a)
		-- fake is pretty close to real
		stage:removeEventListener(Event.ENTER_FRAME, update)
	end
	alpha *= decay
	obj:setAlpha(alpha)
end
 
stage:addEventListener(Event.ENTER_FRAME, update)
And seems like this is exactly how it works, but real code for alpha decay is
alpha=alpha*pow(decay_[i * 4 + 1],nframes);
and I have no idea how to calc that magic alpha decay number >_< Any help?
Also, since it gets multiplied by a factor, you cant set initial alpha to 0, because
0*anyNumber = 0
Maybe it would have been better to replace multiplication with addition/substraction?
E.g. decay = 1/ttl alpha -= decay will decrease alpha exactly from 1 to 0 (or alpha += decay for 0 to 1).
Sign In or Register to comment.