Hi guys!
Here we have a piece of code, where tap on the screen creates new warping up particle emitter under your finger:
– Table of emitter parameters
local emitterParams = {
startColorAlpha = 1,
startParticleSizeVariance = 0,
startColorGreen = 1,
yCoordFlipped = -1,
blendFuncSource = 768,
rotatePerSecondVariance = 0,
particleLifespan = 0.1,
tangentialAcceleration = 0,
finishColorBlue = 1,
finishColorGreen = 1,
blendFuncDestination = 769,
startParticleSize = 512,
startColorRed = 1,
textureFileName = “SomeImage.png”,
startColorVarianceAlpha = 1,
maxParticles = 10,
finishParticleSize = 512,
duration = 0.25,
finishColorRed = 1,
maxRadiusVariance = 0,
finishParticleSizeVariance = 0,
gravityy = 200,
speedVariance = 0,
tangentialAccelVariance = 0,
angleVariance = 0,
angle = 0
}
local function tapEvent( event )
local emitter = display.newEmitter( emitterParams )
emitter.x, emitter.y = event.x, event.y
transition.moveTo( emitter, { x=event.x, y=event.y - 200, time=250, onComplete=function() emitter:removeSelf() emitter = nil end} )
end
Runtime:addEventListener(“tap”, tapEvent)
I’m not clearly understand: is the entire emitter destroyed after it’s life duration or only generated particles are destroyed?
I’ve tested this by printing emitter variable and the result was address of emitter table. This means, emitter still alive after it’s «duration». Just invisible, but alive.
As already was answered in https://forums.coronalabs.com/topic/58503-best-practice-for-removing-particle-objects/ post:
However, that will NOT destroy the emitter object… if you don’t need it anymore (no need for new particles) then you SHOULD remove it outright in your code.
For this, I would suggest that you run a timer simultaneously, and when the timer is completed, you …(remove)… the emitter object.
You can test the code above and see, that if you are tapping fast enough (~2-3 taps per second) only first emitter works well while other new emitters will be generating only few particles from many or generating nothing at all. If you will wait a second after last emitter ended the new one will be working fine once again.
But all works fine and all « fast-tap-created» emitters will work fine without emitter-removing code.
E-e-em-m… What need to be changed in code to make this simple work? Any help, please?