Wave Engine was born on February 21, 2013 with the exciting mission of developing an engine to help the mobile game developers’ community.

Post tutorial Report RSS Particle System

Typically a particle system is a component that uses very small sprites/textures to simulate real life phenomena like fire, clouds, rain, dust, etc. We introduce Wave Engine Particles System feature to see how we can create particles in our games with a very simple torch fire sample.

Posted by on - Basic Client Side Coding

Objectives

Typically a particle system is a component that uses very small sprites/textures to simulate real life phenomena like fire, clouds, rain, dust, etc.

We introduce Wave Engine Particles System feature to see how we can create particles in our games with a very simple torch fire sample.

Create Project

Create a new Game Project from the Wave Engine template, and name it TorchFire:

Create the camera

First thing we are going to need is a camera to see the world from. So, go to MyScene.cs file and add these usings :

using WaveEngine.Components.Cameras;
using WaveEngine.Common.Math;

Now, in CreateScene() method create a camera to be able to see the world in this way:

// Position & LookAt are setted on CameraBehavior
var camera = new FreeCamera("Camera", new Vector3(50, 50, 50), Vector3.Zero)
{
    BackgroundColor = Color.Black
};

EntityManager.Add(camera);

Create Particle System

Before adding the code necessary to create a particle system, we need these usings:

using WaveEngine.Components.Particles;
using WaveEngine.Materials;

After the EntityManager.Add(camera) line, add this code to initialize our particle system:

ParticleSystem3D fireParticle = new ParticleSystem3D()
{
    NumParticles = 18,
    MinLife = TimeSpan.FromSeconds(0.2f),
    MaxLife = TimeSpan.FromSeconds(0.7f),
    LocalVelocity = new Vector3(0.0f, 0.6f, 0.0f),
    RandomVelocity = new Vector3(0.1f, 0.0f, 0.0f),
    MinSize = 3,
    MaxSize = 8,
    MinRotateSpeed = 0.1f,
    MaxRotateSpeed = -0.1f,
    EndDeltaScale = 0.0f,
    EmitterSize = new Vector2(2),
    EmitterShape = ParticleSystem3D.Shape.Circle,
};

Take a look at this table to see what is each parameter for:

NumParticles Gets or sets the number of particles
NumParticles Gets or sets the number of particles
MinLife Gets or sets minimum period of time these particles will last
MaxLife Gets or sets maximum period of time these particles will last
LocalVelocity How much X, Y and Z axis velocity to give each particle
RandomVelocity How much random velocity to give each particle
MinSize Gets or sets the minimum size of the particles
MaxSize Gets or sets the maximum size of the particles
MinRotateSpeed Gets or sets the minimum rotation speed of the particles
MaxRotateSpeed Gets or sets the maximum rotation speed of the particles
EndDeltaScale Gets or sets the end delta scale
EmmiterSize Size of emiter
EmitterShape Emiter shape

There are more properties we can play with in a particle system, but for our sample these are the minimum required.

Create Particle Entity

To make a particle system to show particles we need to create an Entity that use it. So after fireParticle initialization add this code to define the Entity needed:

var fireParticleEntity = new Entity("fire")
     .AddComponent(new Transform3D())
     .AddComponent(fireParticle)
     .AddComponent(new MaterialsMap(new BasicMaterial("Content/particleFire.wpk", DefaultLayers.Additive)
     {
         VertexColorEnabled = true 
     }))
     .AddComponent(new ParticleSystemRenderer3D());
EntityManager.Add(fireParticleEntity);

Note: Do not forget to add the file particleFire.wpk you can find in Resources directory in the sample, and set the Copy to Ouput Directory to Copy Always.

See how we are added the fireParticle system as a component in the Entity. This will apply all physic, behaviors and properties defined previously in the Particle System. Note too, the BasicMaterial we are adding as Additive.

Last thing we left is to add this entity to the scene, so add this line at the end:

EntityManager.Add(fireParticleEntity);

Now you can build and run the sample and see this:

You can move around with keyboard and mouse (W,A,S,D keys).

Example

Here you have another more complete demo about ParticleSystems with different particles effects (rain, snow, etc.) (ParticleSystem3D).

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: