Page 1 of 2

Particles suddenly disappearing

Posted: Fri Apr 12, 2013 7:38 pm
by ayase
I encountered a problem with using particle systems, which I can neither seem to solve myself, nor find anything concerning it on the forums.
Some particles in the system I set up will just suddenly pop out of existence, instead of gradually fading as I thought they should with the colours I assigned to the system (and most particles do in fact fade out as they should). At first I thought I calculated the buffer size wrong, but changing it didn't fix the problem, and if I actually make it too small, there are just fewer particles emitted. I suspected it might have something to do with the particle life, but my experimentation with it hasn't given me a solution either. I still suspect the problem is in particle life somewhere, as some configurations seem to make the problem better or worse, but I can't get it to go away.

We use Tiled (map editor) maps in the .lua format and Tiled objects to define the properties and position of the particle system.

This is the code where the particle systems are initialised:

Code: Select all

if objects[i].type == "PARTICLE" then
			local sprite = love.graphics.newImage("Media/Particles/"..objects[i].properties["image"]);
			local mapParticle = love.graphics.newParticleSystem( sprite, tonumber(objects[i].properties["rate"])*tonumber(objects[i].properties["lifeMax"]));
			mapParticle:setOffset( sprite:getWidth()/2, sprite:getHeight()/2 );
			mapParticle:setLifetime( -1 );
			mapParticle:setSpin(math.rad(objects[i].properties["spinMin"]),math.rad(objects[i].properties["spinMax"]), tonumber(objects[i].properties["spinVar"]));
			mapParticle:setSpeed(tonumber(objects[i].properties["speedMin"]), tonumber(objects[i].properties["speedMax"]));
			mapParticle:setSpread( math.rad(objects[i].properties["spread"]));
			mapParticle:setDirection( math.rad(objects[i].properties["direction"]));
			mapParticle:setParticleLife( tonumber(objects[i].properties["lifeMin"]), tonumber(objects[i].properties["lifeMax"]));
			mapParticle:setRadialAcceleration( tonumber(objects[i].properties["accMin"]), tonumber(objects[i].properties["accMax"]));
			mapParticle:setEmissionRate( tonumber(objects[i].properties["rate"]));
			mapParticle:setSizes( tonumber(objects[i].properties["size1"]), tonumber(objects[i].properties["size2"]));
			mapParticle:setTangentialAcceleration( tonumber(objects[i].properties["tangAccMin"]), tonumber(objects[i].properties["tangAccMax"]));
			mapParticle:setColors(255,255,255,0,255,255,255,255,255,255,255,191,255,255,255,127,255,255,255,63,255,255,255,0);
			mapParticle:setPosition(objects[i].x, objects[i].y);
			table.insert(self.particles, mapParticle);
			self.particles[table.getn(self.particles)]:start();
		end
This is where they are updated:

Code: Select all

function GameMap:updateParticles(dt)
	for i = 1, (table.getn(self.layers[MAP_OBJECT_LAYER].particles)), 1 do
		local xOnScreen = self.layers[MAP_OBJECT_LAYER].particles[i]:getX() -self.cam.x;
		local yOnScreen = self.layers[MAP_OBJECT_LAYER].particles[i]:getY() -self.cam.y;
		if (xOnScreen > -320 and xOnScreen < 748 and yOnScreen > -320 and yOnScreen < 560) then
			self.layers[MAP_OBJECT_LAYER].particles[i]:update(dt);
		end
	end
end
and this is where they are drawn:

Code: Select all

for i = 1, (table.getn(self.layers[MAP_OBJECT_LAYER].particles)), 1 do
		local xOnScreen = self.layers[MAP_OBJECT_LAYER].particles[i]:getX() -self.cam.x;
		local yOnScreen = self.layers[MAP_OBJECT_LAYER].particles[i]:getY() -self.cam.y;
		if (xOnScreen > -320 and xOnScreen < 748 and yOnScreen > -320 and yOnScreen < 560) then
			love.graphics.draw(self.layers[MAP_OBJECT_LAYER].particles[i], -self.cam.x, -self.cam.y );
		end
	end
The rate of the particle system where the problem is obvious is 40, lifeMin is 1, lifeMax is 2.

Thank you for helping in advance, if additional information is needed, I will provide it.

Re: Particles suddenly disappearing

Posted: Fri Apr 12, 2013 10:45 pm
by adnzzzzZ
When do you enter the condition that creates a new particle system?

Re: Particles suddenly disappearing

Posted: Sat Apr 13, 2013 7:50 am
by ayase
The condition is met when the map is created. We have a function called GameMap:init() which loads all the layers. For the object layers, it creates a new object layer instance and calls the function ObjectLayer:init(objects) which iterates over each object in the layer. If the object type is "PARTICLE", a new particle system is created, and stored as an element of the layer's particle table.

I suppose you suspected the system was created multiple times? I just checked that, and it's not the case.
Or is there a special place where you have to initialise particle systems for them to work properly?

Re: Particles suddenly disappearing

Posted: Sat Apr 13, 2013 9:56 am
by T-Bone
If you'd upload a .love, then we could test it and see if the same issue occurs on our machines. It doesn't really sound like a driver issue to me but you never know.

Re: Particles suddenly disappearing

Posted: Sat Apr 13, 2013 2:13 pm
by ayase
I attached an isolated version of the particle emitter that is problematic, and it recreates the problem for me. I suspect the particles might not actually disappear, but are suddenly sorted behind other particles for some reason, but it's hard to tell, even in slow motion.

Re: Particles suddenly disappearing

Posted: Sat Apr 13, 2013 2:40 pm
by adnzzzzZ
I think your suspicion is correct. I noticed similar behavior when playing around with other configurations. The best thing you can do, as far as I know, is to play around with alphas, buffer sizes and emission rates.

Re: Particles suddenly disappearing

Posted: Sat Apr 13, 2013 4:04 pm
by ayase
That's too bad. So it's a problem in the engine? If so, should I submit it to the issue tracker?
Or is it an error on my part? Is there a formula for choosing values where this problem does not occur?

Re: Particles suddenly disappearing

Posted: Sat Apr 13, 2013 5:16 pm
by adnzzzzZ
I honestly don't know the answer to any of your questions. This would be a good time for someone who understands the particle system more than us to say something. :3c

Re: Particles suddenly disappearing

Posted: Thu Apr 18, 2013 9:24 am
by ayase
Can nobody help me? This problem is not resolved, it would be nice if someone who understands the problem could enlighten me. As it is, I can't use the particle system for any dense system with properly shaded particles, as the flicker is immediately obvious. Do I have to write a particle system of my own if I want to adress this? I'm not to keen on that, as it would probably be a hit on performance.

Re: Particles suddenly disappearing

Posted: Thu Apr 18, 2013 6:03 pm
by Boolsheet
Yes, you're correct that the particle draw order is rather random if a variable particle lifetime is used. This is caused by LÖVE's list implementation where the particles are stored. Sadly, I don't know if you can work around it.