Skip to content

Particle system

In Supernova to use particle system you have to two kind of tools: Particle Initializers and Particle Modifiers.

  • Particle Initializers
    • Life
    • Position
    • Velocity
    • Acceleration
    • Color
    • Alpha
    • Size
    • Sprite
    • Rotation
  • Particle Modifiers
    • Position
    • Velocity
    • Acceleration
    • Color
    • Alpha
    • Size
    • Sprite
    • Rotation

Particles live sample

Here is an example how Inittializers and Modifiers can be used to create particles animation.

#include "Supernova.h"
using namespace Supernova;

#include "Particles.h"
#include "ParticlesAnimation.h"

Scene scene;

Particles particles(&scene);
ParticlesAnimation partianim(&scene);

void init(){
    particles.setMaxParticles(100);
    particles.setTexture("f4.png");
    particles.setPosition(300, 100, 0);
    partianim.setTarget(particles.getEntity());

    partianim.setRate(10);

    partianim.setLifeInitializer(10);
    partianim.setPositionInitializer(Vector3(0,0,0), Vector3(300,0,0));
    partianim.setVelocityInitializer(Vector3(0,10,0), Vector3(0,50,0));
    partianim.setColorInitializer(Vector3(0,0,0), Vector3(1,1,1));
    partianim.setSizeInitializer(10, 50);

    partianim.setVelocityModifier(5, 8, Vector3(0,10,0), Vector3(0,300,0), EaseType::CUBIC_IN_OUT);
    partianim.setAlphaModifier(4, 6, 1, 0.2);

    Engine::setScene(&scene);

    partianim.start();
}
scene = Scene()

particles = Particles(scene)
partianim = ParticlesAnimation(scene)

particles.maxParticles = 100
particles:setPosition(300, 100, 0)
particles:setTexture("f4.png")
partianim.target = particles.entity

partianim.rate = 10

partianim:setLifeInitializer(10)
partianim:setPositionInitializer(Vector3(0,0,0), Vector3(300,0,0))
partianim:setVelocityInitializer(Vector3(0,10,0), Vector3(0,50,0))
partianim:setColorInitializer(Vector3(0,0,0), Vector3(1,1,1))
partianim:setSizeInitializer(10, 50)

partianim:setVelocityModifier(5, 8, Vector3(0,10,0), Vector3(0,300,0), EaseType.CUBIC_IN_OUT)
partianim:setAlphaModifier(4, 6, 1, 0.2)

Engine.setScene(scene)

partianim:start()

Particle Initializers

Life Initializer

Every particle has its life and this life is regressive. When a particle starts, through this class you can set the lifetime of it. Throughout the life of the particle, when it reaches 0, the particle dies.

partianim.setLifeInitializer(10, 10);
partianim:setLifeInitializer(10, 10)

Position Initializer

The initial position of particle.

partianim.setPositionInitializer(Vector3(0,0,0), Vector3(300,0,0));
partianim:setPositionInitializer(Vector3(0,0,0), Vector3(300,0,0))

Velocity Initializer

It's the initial velocity of particle.

partianim.setVelocityInitializer(Vector3(0,10,0), Vector3(0,50,0));
partianim:setVelocityInitializer(Vector3(0,10,0), Vector3(0,50,0))

Acceleration Initializer

It's to set inital acceleration of particle with this class.

partianim.setAccelerationInitializer(Vector3(0,100,0), Vector3(0,200,0));
partianim:setAccelerationInitializer(Vector3(0,100,0), Vector3(0,200,0))

Color Initializer

Can be used to set initial color of particle.

partianim.setColorInitializer(Vector3(0,0,0), Vector3(1,1,1));
partianim:setColorInitializer(Vector3(0,0,0), Vector3(1,1,1))

Alpha Initializer

It can be used to set particle transparency. When set 0 is total transparent particle, when set 1.0 is total opaque particle.

partianim.setAlphaInitializer(0, 1);
partianim:setAlphaInitializer(0, 1)

Size Initializer

Every particle can have its size. This class is used to set initial size of particle.

partianim.setSizeInitializer(10, 50);
partianim:setSizeInitializer(10, 50)

Sprite Initializer

A particle can also have behave like a sprite. The sprite of particle is set by an integer and during particle creation the initial sprite is sorted.
In Supernova we call sprite as a rect of sprite sheet.

std::vector<int> sprites;
sprites.push_back(1);
sprites.push_back(0);
sprites.push_back(2);
partianim.setSpriteIntializer(sprites);
partianim:setSpriteIntializer({1, 0, 2})

Rotation Initializer

The initial rotation of particle is set with this class. The engine default is degress, but it can be changed.

partianim.setRotationInitializer(90, 90);
partianim:setRotationInitializer(90, 90)

Particle Modifiers

Position Modifier

This modifier makes all particles travel from start position to end position in determined time.

partianim.setPositionModifier(2, 4, Vector3(0,0,0), Vector3(0,300,0));
partianim:setPositionModifier(2, 4, Vector3(0,0,0), Vector3(0,300,0))

Velocity Modifier

This modifier changes particle velocity in determined time.

partianim.setVelocityModifier(5, 8, Vector3(0,10,0), Vector3(0,300,0));
partianim:setVelocityModifier(5, 8, Vector3(0,10,0), Vector3(0,300,0))

Acceleration Modifier

This modifier changes acceleration in determined time.

partianim.setAccelerationInitializer(Vector3(0,100,0), Vector3(0,200,0));
partianim:setAccelerationInitializer(Vector3(0,100,0), Vector3(0,200,0))

Color Modifier

This modifier changes color particle in determined time.

partianim.setColorModifier(2, 5, Vector3(1,1,1), Vector3(1,0,0));
partianim:setColorModifier(2, 5, Vector3(1,1,1), Vector3(1,0,0))

Alpha Modifier

This modifier changes alpha from particle in determined time.

partianim.setAlphaModifier(4, 6, 1, 0.2);
partianim:setAlphaModifier(4, 6, 1, 0.2)

Size Modifier

This modifier changes size of particle in determined time.

partianim.setSizeModifier(1, 3, 10, 50);
partianim:setSizeModifier(1, 3, 10, 50)

Sprite Modifier

This modifier changes sprite animation of particle in determined time.

partianim.setSpriteModifier(5, 8, {0,1,2});
partianim:setSpriteModifier(5, 8, {0,1,2})

Rotation Modifier

This modifier changes rotation of particle in determined time.

partianim.setRotationModifier(1, 5, 0, 360);
partianim:setRotationModifier(1, 5, 0, 360)