BlendELF is a engine written by me, an IT student at the University of Jyväskylä. I am coding the engine as my portfolio project, as a proof of my skills in 3d graphics and game logics/systems coding. I release this engine under the assumption that it could be useful for other people in making quck prototypes and small games. I reserve the right to halt the development of this engine at will, at any given time.
Tutorial 7, Particles
This tutorial builds on the first tutorial, so be sure to do that first! [Tutorial 1, BlendELF Basics]. This tutorial should give you a basic idea how to use the BlendELF GUI system.
Step 1: Getting the tutorial resources
[tutorial7_resources.zip] contains the particle sprite we are going to use in this tutorial.
Step 2: Extracting the tutorials resources
The tutorial resource package contains a folder called resources. Copy and paste that folder to the folder where you have your BlendELF Developmet Kit.
Step 3: Simple particle system
For this tutorials base init.lua, we will start with a simple script that loads a level (the same as in Tutorial 1) and runs the engine.
scn = elf.LoadScene("level1.pak") while elf.Run() == true do end
All good so far. Now we will create a simple particle system.
scn = elf.LoadScene("level1.pak") par = elf.CreateParticles("MyParticles", 1000) elf.SetActorPosition(par, 0.0, 0.0, 3.0) elf.AddParticlesToScene(scn, par) while elf.Run() == true do end
Try running the engine now. You should see some particles spawning above the ground.

So what happened there? We created a particle system with the name "MyParticles" and with the particle cap of 1000 particles. The second argument of elf.CreateParticles is the maximum amount of particles which the particle system will allow to be created. The bigger the value, the more memory it takes. You can later on change the value with elf.SetParticlesMaxCount if you want.

Next me set the position of the particle system, and finally we add the particle system to the scene. Simple enough, isn't it?
Step 3: Texture, Color, Size
Next we will set a texture for the particles.
scn = elf.LoadScene("level1.pak") partex = elf.CreateTextureFromFile("resources/particle.png") par = elf.CreateParticles("MyParticles", 1000) elf.SetParticlesTexture(par, partex) elf.SetActorPosition(par, 0.0, 0.0, 3.0) elf.AddParticlesToScene(scn, par) while elf.Run() == true do end
Now you should see some round particles. Lets add some variable color next.
scn = elf.LoadScene("level1.pak") partex = elf.CreateTextureFromFile("resources/particle.png") par = elf.CreateParticles("MyParticles", 1000) elf.SetParticlesTexture(par, partex) elf.SetParticlesColorMin(par, 0.5, 0.5, 0.5, 1.0) elf.SetParticlesColorMax(par, 1.0, 1.0, 1.0, 1.0) elf.SetActorPosition(par, 0.0, 0.0, 3.0) elf.AddParticlesToScene(scn, par) while elf.Run() == true do end
Nice, now we have some colored particles. Lets set a variable size next.
scn = elf.LoadScene("level1.pak") partex = elf.CreateTextureFromFile("resources/particle.png") par = elf.CreateParticles("MyParticles", 1000) elf.SetParticlesTexture(par, partex) elf.SetParticlesColorMin(par, 0.5, 0.5, 0.5, 1.0) elf.SetParticlesColorMax(par, 1.0, 1.0, 1.0, 1.0) elf.SetParticlesSize(par, 0.25, 1.0) elf.SetActorPosition(par, 0.0, 0.0, 3.0) elf.AddParticlesToScene(scn, par) while elf.Run() == true do end
You probably noticed that the size doesn't have two functions, one for min and one for max. Instead the size has only one function which sets both, the min and the max of the variable size.
Step 4: Velocity, Gravity, Spawn Delay
Lets say we wan't to make a fountain. First thing would be to set the variable velocity to spread the particles upwards.
scn = elf.LoadScene("level1.pak") partex = elf.CreateTextureFromFile("resources/particle.png") par = elf.CreateParticles("MyParticles", 1000) elf.SetParticlesTexture(par, partex) elf.SetParticlesColorMin(par, 0.5, 0.5, 0.5, 1.0) elf.SetParticlesColorMax(par, 1.0, 1.0, 1.0, 1.0) elf.SetParticlesSize(par, 0.25, 1.0) elf.SetParticlesVelocityMin(par, -3, -3, 7.0) elf.SetParticlesVelocityMax(par, 3, 3, 7.0) elf.SetActorPosition(par, 0.0, 0.0, 3.0) elf.AddParticlesToScene(scn, par) while elf.Run() == true do end
Nice, now they are spreading upwards. Next we add some gravity to them.
scn = elf.LoadScene("level1.pak") partex = elf.CreateTextureFromFile("resources/particle.png") par = elf.CreateParticles("MyParticles", 1000) elf.SetParticlesTexture(par, partex) elf.SetParticlesColorMin(par, 0.5, 0.5, 0.5, 1.0) elf.SetParticlesColorMax(par, 1.0, 1.0, 1.0, 1.0) elf.SetParticlesSize(par, 0.25, 1.0) elf.SetParticlesVelocityMin(par, -3, -3, 7.0) elf.SetParticlesVelocityMax(par, 3, 3, 7.0) elf.SetParticlesGravity(par, 0, 0, -20.0) elf.SetActorPosition(par, 0.0, 0.0, 3.0) elf.AddParticlesToScene(scn, par) while elf.Run() == true do end
Assuming that at this point, we wan't more particles, we just set the spawn delay smaller. The amount of particles in existance at once can be counted with life_span/spawn_delay. Lifespan can be set with elf.SetParticlesLifeSpan. Both the life span, spawn delay (and fade speed) are set in seconds.
scn = elf.LoadScene("level1.pak") partex = elf.CreateTextureFromFile("resources/particle.png") par = elf.CreateParticles("MyParticles", 1000) elf.SetParticlesTexture(par, partex) elf.SetParticlesColorMin(par, 0.5, 0.5, 0.5, 1.0) elf.SetParticlesColorMax(par, 1.0, 1.0, 1.0, 1.0) elf.SetParticlesSize(par, 0.25, 1.0) elf.SetParticlesVelocityMin(par, -3, -3, 7.0) elf.SetParticlesVelocityMax(par, 3, 3, 7.0) elf.SetParticlesGravity(par, 0, 0, -20.0) elf.SetParticlesSpawnDelay(par, 0.01) elf.SetParticlesLifeSpan(par, 1.5, 2.0) elf.SetActorPosition(par, 0.0, 0.0, 3.0) elf.AddParticlesToScene(scn, par) while elf.Run() == true do end
That should give you a REALLY shiny fountain...

In addition to the particle parameters introducet in this tutorial, there are some more of them, like fade speed and variable position. Also you can set a mesh for the particle system and the particles with be spawned according to the vertices of the mesh. Check the API documentation for more information.

Thats it! I hope you enjoyed the tutorial, and if you have any comments about it, please post to the forums.