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).
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"
local realParticles = Particles.new()
ttl = ttl,
decayAlpha = decay,
alpha = alpha,
x = 150, y = 50,
size = 100,
color = 0,
frames += 1
if (frames > ttl) then
print("Fake alpha:", alpha)
print("Real alpha:", a)
-- fake is pretty close to real
alpha *= decay
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
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).