Burst Particles?

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.
Post Reply
User avatar
joedono
Prole
Posts: 40
Joined: Mon Mar 04, 2013 6:58 pm

Burst Particles?

Post by joedono »

I'm using the love.graphics ParticleSystem class for particle effects in my top-down dungeon crawler. The problem I'm having is that a lot of my effects are "burst" based, meaning I need the particle system to emit a whole bunch of particles in one frame, update and draw those particles (without emitting any more), then reset the system and get ready for the next time I need that effect. Some effects I need are a short spurt of blood when the player is hit and a spark burst when their weapon hits a solid object.

The only way I've found to do this with love's particle system is to set the buffer size very small (15 particles), set the emission rate very high (2000 particles/second), and set the system lifetime very short (0.1 seconds). The problem with this approach is that I have to have a single set particle lifetime that's equal to the system lifetime. I can't set the particle lifetime to a range. If I want the particle life to be longer, they'll disappear before their life is up. If I want the particle life to be shorter, I lost the "burst" quality of the effect because more particles will be emitted before the system lifetime runs out.

I can probably tweak what I have to get the effect I want, but this would be a lot simpler if the library supported some kind of addParticles(num) or burstParticles(num) function. Am I just not seeing some piece of the documentation? Has anyone else run in to this? What can I do? I'd rather not build my own particle system if there's a better solution out there.
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

Re: Burst Particles?

Post by Germanunkol »

I would not use a particle system, but an animated sprite for this. It will probably be much less CPU-intensive.

If you still want to use your already existing code, try this:
  • Make a new project in love, set the window size to the size of the animated image you want (maybe 50x50 pixels).
  • If you need transparency, set the background to black
  • Render the effect, and make a screenshot every time, use the screenshot function.
  • Then make a new imageData, and use the paste function to paste the screenshots into the new imageData, next to each other.
  • Save the new imageData using the imageData:encode() function
  • For transparency, load the image in the GIMP, go to Colors -> Color to alpha -> choose black and press Ok
Now you have a sprite which you can animate.

This way you can easily render 3 or 5 versions of the effect, which all look a little random, and then randomly use them in-game. It'll probably look pretty good.
Once you have this procedure set up (which should take no more than an hour) it'll be easy to make lots of effects like this.
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
User avatar
joedono
Prole
Posts: 40
Joined: Mon Mar 04, 2013 6:58 pm

Re: Burst Particles?

Post by joedono »

I suppose I can give this a shot. It has the downside that, if I want to tweak my effect later, I'll have to regenerate the sprite sheet.

On the other hand, it will give me an excuse to use some parts of Love2D that I wouldn't have tried otherwise.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Burst Particles?

Post by kikito »

If I want the particle life to be longer, they'll disappear before their life is up. If I want the particle life to be shorter, I lost the "burst" quality of the effect because more particles will be emitted before the system lifetime runs out.
I have never actually used LÖVE's particle system, but isn't this what ParticleSystem:setLifetime and ParticleSystem:setParticleLife are for?
When I write def I mean function.
User avatar
joedono
Prole
Posts: 40
Joined: Mon Mar 04, 2013 6:58 pm

Re: Burst Particles?

Post by joedono »

That's exactly what they are for. What I was trying to say is that I have to set them to the same value. I can't use ParticleSystem:setParticleLife(1, 3) because I won't know what to set the ParticleSystem Lifetime to.

If I set the system lifetime to 1, the particles that live for 3 seconds will disappear before their life runs out. If I set the system lifetime to 3, then some particles will die after 1 second and there will be room in the buffer for more particles to be emitted (which will remove the Burst effect I'm looking for).

I've tweaked the settings enough to get the effect I want, and it doesn't sound like there's a ParticleSystem:burstParticles() function that I missed. It might be a good (cheap) feature for the Love devs to implement in a future release.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Burst Particles?

Post by kikito »

In that case you might have found a bug, or at least an incorrect method description. On the wiki it says that setLifetime
Sets how long the particle system should emit particles (if -1 then it emits particles forever).
If I'm understanding you correctly, when the time passes, it doesn't only "stops emitting particles". It also removes any existing ones, no matter how "young" they are.

The only other option I can think of is creating several individual emitters instead of just one. So, if you want 15 particles, you create 15 emitters that throw 1 particle each. I don't know how efficient that would be though.
When I write def I mean function.
User avatar
timmeh42
Citizen
Posts: 90
Joined: Wed Mar 07, 2012 7:32 pm
Location: Cape Town, South Africa

Re: Burst Particles?

Post by timmeh42 »

I may be misunderstanding this, but why can't you just set up your system, set an alarm for 1 frame, and set the emission rate to 0 after that?
User avatar
joedono
Prole
Posts: 40
Joined: Mon Mar 04, 2013 6:58 pm

Re: Burst Particles?

Post by joedono »

kikito wrote:If I'm understanding you correctly, when the time passes, it doesn't only "stops emitting particles". It also removes any existing ones, no matter how "young" they are.
You just inspired me to build a quick experiment. Apparently, you can still call a ParticleSystem's update() and draw() function even after the system's lifetime has run out. I had been checking if it was active manually before bothering to update or draw the system. Now I can set a particle's lifetime to longer than the system lifetime, as long as the system's lifetime is extremely short and the emission rate is extremely high, I get the effects I want.

Thanks!

Still though, if the Love devs see this, it'd probably be dirt-easy to build a ParticleSystem:burstParticles(num) function. I'll throw this up on BitBucket as a feature request. I'd give it a shot myself, but I don't know C++.
User avatar
yared0319
Prole
Posts: 4
Joined: Thu Jan 19, 2012 2:44 am

Re: Burst Particles?

Post by yared0319 »

joedono wrote:The problem I'm having is that a lot of my effects are "burst" based, meaning I need the particle system to emit a whole bunch of particles in one frame, update and draw those particles (without emitting any more), then reset the system and get ready for the next time I need that effect.
I recently ran into the same problem, joedono, and ended up using VRLD's timer library (similar to timeh's idea) to stop the burst after a short amount of time.

Code: Select all

dust:setEmissionRate(100)
dust:start()
-- stop the burst fx after some time
_timers.dust = Timer.add(0.01, function() dust:pause() end)
EDIT: I was going through the latest commits to see what the Inner Party is up to and was happy to see that they've taken your advice and added an "emit" particles method. Pretty cool.

Kikito and Germanunkol: For new LÖVE developers, the particle system seems like a very straightforward and simple way of getting started with effects. Maybe the particle system doesn't scale well, though? What do you recommend as alternatives for creating and tracking particle-style effects?

Thanks.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 3 guests