Advertisement

Particle Engine questions...

Started by February 14, 2003 03:00 AM
12 comments, last by exepotes 21 years, 9 months ago
I also have particle system code, here if you want.


Gamedev for learning.
libGDN for putting it all together.
An opensource, cross platform, cross API game development library.
VSEDebug Visual Studio.NET Add-In. Enhances debugging in ways never thought possible.
Well, you are a very colaborative community. Thank you, people!!
-----------------------------------------------------------Web Comic
Advertisement
Oh, and I do understand french, so I''ll check AP''s web.
-----------------------------------------------------------Web Comic
quote: Original post by Machaira
Here''s one link I found:
Building an Advanced Particle System

Particle systems aren''t a beginner subject. You might want to consider something easier until you get more experience.

[edited by - Machaira on February 14, 2003 9:35:12 AM]


Wrong. Particle engines are actually quite easy to implement, ESPECIALLY in 2D. Though in a game, that''s an other matter. Personally, I had absolutely no problem getting mine to work on my first try.

Simply create an array for, say, 200 particles. Hell, use QBasic or VB; you''re just trying to learn the theory, not code something in your game yet.

The arrays should include...
-An X and Y position array.
-An X and Y velocity array.
-A color array, the ''life'' of your particle.

Ok... let''s say we want to make a fountain. For the sake of simplicity, I''ll assume you have a 640x480 window do draw in. So initialize X to ~320, and Y to 640 for every particle. Then give the X velocity array a value from, say, -8 to 8, and Y from 0 to -4.

Every frame, you want to update your particles: erease the old one, update the position, and draw the new one. This can be as simple as drawing at the ''current'' position (X and Y arrays, remember?) a black pixel or whatever the BG color is, then doing something like this...

X[CurrentParticle] += XVelocity[CurrentParticle];
Y[CurrentParticle] += YVelocity[CurrentParticle];
XVelocity[CurrentParticle] *= .98;
YVelocity[CurrentParticle] *= .98 + .1;

What this does is move the particle, then reduce its speed a little. Additionally, we make it fall so it doesn''t just stop after reaching its max height and stick there. You should then reduce the color by 1 (and generate a new particle if it reaches 0) and plot at the new position with Color[CurrentParticle] intensity.

This is actually an extremely simplified particle engine and could be expanded on a LOT. Transparent pixels, trails, so forth... If you want, I could give you some example source in QBasic, VB, C++ with directx OR the win32 API.

Hope this helps. Just experiment. This is just an extremely basic outline and wouldn''t work too well in a 3D environment, but for 2D it''s a piece of cake to fit in your game.

This topic is closed to new replies.

Advertisement