In my rewrite of CBEffects, I’ve come across a very odd issue. The way particles’ “lifetimes” are dealt with is by transitions (transition.to, to be specific) for the alpha. After a transition is finished, the next is started within the original one’s onComplete function. Then, at the end of the final transition, a kill function is called (deletes the particle, removes stored references, etc) and everything’s fine.
My problem? When I delete more than one particle at a time (through a loop), something is taking far too long to execute when the particle is killed. I’ve isolated the problem down to transition.cancel. When I comment out the line that cancels any remaining transition, multiple particle deletion finishes at a normal speed. But un-comment it? Almost a second and a half to delete 120 particles (which may seem like a lot, but without the line, you can’t even see a flicker in the application speed).
I won’t post the whole library (for obvious reasons), but here is a simplified version of the only relevant areas. The variable “p” refers to the particle; transition_cancel and transition_to are both localized forms of transition functions.
[lua]
function p._kill()
– This is the offending line
if p._cbe_reserved.transition then transition_cancel(p._cbe_reserved.transition) end – _cbe_reserved is a cache that holds reserved properties
display_remove§
[/lua]
[lua]
– Set Up Particle Transition
p._cbe_reserved.transition = transition_to(p, {
alpha = p.lifeAlpha,
time = vent.inTime,
onComplete = function()
p._cbe_reserved.transition = transition_to(p, {
alpha = vent.endAlpha,
delay = vent.lifeTime,
time = vent.outTime, – Time before particle is killed
onComplete = p._kill – Call the _kill function at the end
})
end – onComplete
})
[/lua]
Why is this happening? Can it be fixed, or is it simply a quirk of the new transition API?
- C