This include file contains often used, small particle effect related functions, such as emulating a particle effect with sprites. The functions are simple enough to understand them at a glance. If you want to modify them, please edit a particles.c copy in your work folder, and not the original file in the include folder.
effect_sprite(STRING* image, EVENT func, var number, VECTOR* pos, VECTOR* vel)
Emulates a particle effect similar to effect_local, but with sprites (or models) instead of particles.
||STRING* or char*; sprite or model filename to be used as particle image, or NULL for a default particle.
||Particle function; runs every frame.
||Number of particles to create.
||Position of the particle emitter.
||Initial speed vector.
- Advantage of particle emulation: sprites or models can have any size and rotation, are distance sorted when transparent, can perform collision detection when desired,
and can use shaders
. Disadvantage: rendering and creating sprites or models is much slower than rendering and creating particles.
- The emulated particle function (func) looks almost like a normal particle function, but some particle-specific parameters and flags are replaced by entity skills
skill60..69 and FLAG7
: vel_x/y/z => _VEL_X/Y/Z; gravity => _GRAVITY; size => _SIZE; lifespan => _LIFESPAN; you => _CREATOR;
MOVE => _MOVE
. BEAM and STREAK are not supported.
- Every emulated particle adds a function to the scheduler that runs during its lifespan. Adjust max_entities and nexus if necessary.
// original particle function
function p_fountain(PARTICLE* p)
set(p, MOVE | BRIGHT | TRANSLUCENT);
p.alpha = 100;
p.size = 2;
p.gravity = 0.2;
p.skill_a = 3; // fade factor
p.event = p_fade;
// sprite-emulated particle function
function p_fountain_sprite(ENTITY* p)
set(p, _MOVE | BRIGHT | TRANSLUCENT);
p.alpha = 100;
p._SIZE = 2;
p._GRAVITY = 0.2;
p._FADE = 3; // fade factor
p.event = p_fade_sprite;
max_entities = max_particles;
if (key_s) // emulated particles
else // original particles
vec_randomize (VECTOR* vec, var range)
Set a vector to a random length and orientation; useful for particle explosions (see example above).
vec - vector to be set to random values.
range - maximum vector length.
p_fade (PARTICLE* p)
p_fade_sprite (ENTITY* p)
Fade a translucent particle resp. emulated particle out and removes it when it becomes fully transparent. The fade speed can be given by the skill_a resp. _FADE parameter of the particle (see example above).
p_follow (PARTICLE* p)
p_follow_sprite (ENTITY* p)
Let a particle follow the creator entity. Uses particle skill_x/_y/_z resp. entity skill70..72.
p_snow (PARTICLE* p)
Let a particle fall slowly to the ground like a snowflake. The wind speed vector is given by vel_x/_y/_z. The particle is placed at a random position at the upper boundary of the camera frustum, and removed when it reaches the lower boundary of the frustum. Uses skill_z.
Example: See samples\weather.c