Particle effect?

BlitzMax Forums/BlitzMax Programming/Particle effect?

Amon(Posted 2007) [#1]
How would I go about creating those particle effects you see in some games where stars, particles etc flow from the curser position?


CS_TBL(Posted 2007) [#2]
Make a list or array of 'things' (these are your particles). Update each particle individually, and when some condition is met, e.g. the particle is out of the screen, or it surpassed some maximum time to live, then you reset that particle again with new settings. Easy as cake!


Dreamora(Posted 2007) [#3]
I would use a particle emitter which is at the cursors position with spread angle of 360 (ie emitting in all directions) but at a very low speed which will reduce over time.

With that they will "fly" out the cursor but stop very quick and if you move the cursor the effect will "follow" your mouse.

The most trickiest thing in that effect is the life time of the particles and if desired potential color changes and alpha change.

But all in all shouldn't be to hard to do :)


Grey Alien(Posted 2007) [#4]
It's all in the framework dude...

But basically build a list where you can store sprites in (to keep track of them and to iterate through them to process them). Each sprite is a moving particle. Set each particle up with an x,y coord and make y alter with gravity(*Delta) over time. Also make them fade over time (again use Delta). When faded, remove them from the list so the Garbage Collector can kill them off. As for generating them, try something like:

If rand(1,100)<10*Delta then
   MakeNewParticle()
EndIf


And tweak the numbers until you have enough of them.

To make the particles look extra cool, try a) fading them in quickly, b) sustaining full Alpha for a certain time c) fading them out slowly. To do this each particle sprite will need some extra code. Again my framework does this with particle animation scripts of sorts.

Don't forget to keep logic and drawing separate.


CS_TBL(Posted 2007) [#5]
Look at the reactions coming :P

I once made some cool stuff on my notebook in the train. The essential problem is that you can go on add things 'n particle behaviour until you drop. Where to call it a day?


Grey Alien(Posted 2007) [#6]
Well these days the polish takes a LONG time and it's what sells the game, so you don't stop too soon...


CS_TBL(Posted 2007) [#7]
Another is the actual behaviour. Are you going to hardcode it all, or are you going to make a scripting system in which you can *everything* you can come up with? This alone takes quite a while. And one could say: "yeahwell, some simple fountain and I guess that's it", but you know how creativity works: you always want more, because each implementation of an idea gives ideas for at least 4 other ideas. Besides, one could argue that something like a flame or waterdrop or whatever is so complex that a simple 'n quick algo won't do.