Particles suddenly disappearing

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
ayase
Prole
Posts: 6
Joined: Fri Apr 12, 2013 6:59 pm

Particles suddenly disappearing

Post 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.
User avatar
adnzzzzZ
Party member
Posts: 305
Joined: Sun Dec 26, 2010 11:04 pm
Location: Porto Alegre, Brazil

Re: Particles suddenly disappearing

Post by adnzzzzZ »

When do you enter the condition that creates a new particle system?
User avatar
ayase
Prole
Posts: 6
Joined: Fri Apr 12, 2013 6:59 pm

Re: Particles suddenly disappearing

Post 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?
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Particles suddenly disappearing

Post 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.
User avatar
ayase
Prole
Posts: 6
Joined: Fri Apr 12, 2013 6:59 pm

Re: Particles suddenly disappearing

Post 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.
Attachments
ParticleTest.love
All the values are copied from the actual object.
(7.37 KiB) Downloaded 155 times
User avatar
adnzzzzZ
Party member
Posts: 305
Joined: Sun Dec 26, 2010 11:04 pm
Location: Porto Alegre, Brazil

Re: Particles suddenly disappearing

Post 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.
User avatar
ayase
Prole
Posts: 6
Joined: Fri Apr 12, 2013 6:59 pm

Re: Particles suddenly disappearing

Post 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?
User avatar
adnzzzzZ
Party member
Posts: 305
Joined: Sun Dec 26, 2010 11:04 pm
Location: Porto Alegre, Brazil

Re: Particles suddenly disappearing

Post 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
User avatar
ayase
Prole
Posts: 6
Joined: Fri Apr 12, 2013 6:59 pm

Re: Particles suddenly disappearing

Post 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.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Particles suddenly disappearing

Post 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.
Shallow indentations.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 10 guests