Sparticles Engine : Particle engine developed by sparkonLINKS TO IMAGES
http://postimage.org/image/mm3mbwy69/]http://postimage.org/image/mm3mbwy69/]http://postimage.org/image/mm3mbwy69/http://postimage.org/image/q3fx7zj85/( don't blame me for imagination )
Hello guys! this is my first "big" project with SFML, it maybe stupid for most of you, but for me it's really important. I was coding my game when i felt the need to create a particle engine, but i didn't want a costum-made one just for my game so i wrote this. It's a simple particle engine based on SFML 2.0 and nothing else.
As soon as i'll post this i'll write a couple of tutorials on how to use it, even though it will become clear while reading its features.
FEATURESThe library is composed by two main classes :
-> DirectionalEmitter
-> ExplosionEmitteras the names suggest they have been create with two different purposes, even though if you work out your directionalemitter you can achieve pretty much ( not exactly) the same effect of the explosionemitter.
Since for the two emitters there are a lot of data that you need ( position, heading,speed,blending etc.....) i've created two costum structs to make the construction easier :
-> DirectionalEmitterMode
-> ExplosionEmitterModeThey work the same way of sf::VideoMode :
-> you initialize them
-> you choose your values
-> you put it in the Emitter constructorSince there are a lot of variables, you can choose to initialize it with pre-defined values and tweak them later or hardcode them directly in the constructor. To make the whole thing working there is just 1 thing that you absolutely have to do before constructing the emitter, and it is :
CHOOSING THE PARTICLESparticles emitter allows you to use 4 different kinds of "look" for your particles :
1 - TEXTURE Use your asset - fast,but not the fastest
2 - CONVEX SHAPE choose your cool shape - slowest one
3 - CIRCLE SHAPE
4 - PIXEL ARRAY Just pass the size of the screen and the color you want! easiest and fastestEverything it's really straighforward. For the Pixel array i've added a few modes ( more will come in the future ) to make the effect really cool :
-> Color Range Avaiable for both emitters
-> Rainbow Mode DirectionalEmitter
-> RandomColor ExplosionEmitterAgain.. as the names suggest you can choose a random color within a predefined range, rainbow mode starting from a predefined range.
Color Range in my opinion is the best one, the particle will start from color A (you choose it ) and will change color ( based on lifetime ) til dying with color B ( you choose it ofc).
ENGINEThe last class you need to be aware of is the ParticleEngine that is nothing else than a higher-level wrapper to manage all your emitters. Every emitter has got his own ID you can access from. You add an emitter by passing its pointer and then place an Update in your main loop.
LINKSThe project is hosted on GitHub, but i've also added a link to mediafire.
In the ZIP file you'll find :
-> compiled headers (debug and release)
-> source code
-> include ( with headers file )
-> Tutorial ( not yet, i'll post it as soon as i can )
P.S : Excuse my english please.
MEDIAFIREhttp://www.mediafire.com/?1bben2471vl229cGITHUB PROJECThttps://github.com/sparkon/SparticlesCODE SAMPLES
Sample Explosion with pixels
#include "sparticles.h"
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow Window(sf::VideoMode(800,600,32),"PARTICLE SYSTEM TEST");
sp::ParticleEngine Engine;
Window.setFramerateLimit(120);
sp::ExplosionEmitterMode dmode(sp::Vector2D(400,300));
dmode.set_pixel_array(sf::Color(255,0,0),sf::Color(255,255,0));
dmode.n_of_particles_ = 6000;
dmode.life_time_ = 100;
dmode.blend_mode_ = sf::BlendAdd;
dmode.random_speed_ = 1;
sp::ExplosionEmitter* emitt = new sp::ExplosionEmitter(Window,dmode);
unsigned int ID = Engine.NewEmitter(emitt);
sf::Clock clock;
while ( Window.isOpen())
{
sf::Event Event;
while ( Window.pollEvent(Event))
{
switch(Event.type)
{
case sf::Event::Closed :
Window.close();
break;
default :
break;
}
}
Window.clear(sf::Color(0,0,0));
sf::Time dt = clock.restart();
Engine.Update(dt);
Window.display();
}
return 0;
}
Directional emitter sample
#include "sparticles.h"
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow Window(sf::VideoMode(800,600,32),"PARTICLE SYSTEM TEST");
sp::ParticleEngine Engine;
Window.setFramerateLimit(120);
sp::DirectionalEmitterMode dmode(sp::Vector2D(0,0));
dmode.set_texture("Particle0.png");
dmode.n_of_particles_ = 10000;
dmode.burst_rate = 0.001;
dmode.life_time_ = 150;
dmode.reuse_ = true;
dmode.blend_mode_ = sf::BlendAdd;
sp::DirectionalEmitter* emitt = new sp::DirectionalEmitter(Window,dmode);
unsigned int ID = Engine.NewEmitter(emitt);
sf::Clock clock;
while ( Window.isOpen())
{
sf::Event Event;
while ( Window.pollEvent(Event))
{
switch(Event.type)
{
case sf::Event::Closed :
Window.close();
break;
default :
break;
}
}
Window.clear(sf::Color(0,0,0));
sf::Time dt = clock.restart();
Engine.Update(dt);
Window.display();
}
return 0;
}