SDL 2D particles tutorial

Started by
2 comments, last by arka80 10 years, 3 months ago

Does anyone recommend a good SDL 2D particles tutorial?

Advertisement

It's not that difficult to have a working particle system:

create a Particle class (or struct) with attributes like

position

speed

direction

color / texture

size

life (how much time it "lives")

elapsed (start from 0 and increase at each frame by the amount of milliseconds elapsed)

then create a ParticleManager / Engine / whatever that

- take care of start a particle effect

- updates each particle every frame

- destroys the particle effect at end

So, your particle engine will have to generate at some position given by you a certain number of Particles, each with a random position near its origin, a speed, a color etc.

At every frame check if

foreach p in Particles -> p.elapsed >= p.life

If yes, kills the particle, if not update its position by its speed and direction (and maybe color alpha)

When no particles remains, destroy and clear all.

Really, it's a nice and funny piece of code to work with and do some experiments

You just wrote quite a nice guide, thank you! You should think about writing more of it with further detail. :)

ahah thank you

I wrote something in my native language (italian) on a blog of mine, but I'm not confident enough with my english to do more.

Anyway, just to add something to the topic, you can learn a lot by reading how other popular frameworks do the work. I have learned much this way, for example by the irrlicht engine code, which is very clear.

This topic is closed to new replies.

Advertisement