Getting Started with LinearParticle


This page explains how to get started with LinearParticle. To have a particle effect, at least one L_Particle object and one L_ParticleEffect ( L_DroppingEffect, L_ShootingEffect or L_ExplosionEffect ) object have to be created.

The following shows the simple initialization with a dropping effect and basic particle setting.
/* initialize LinearParticle, this is the first thing you need to do before using LinearParticle. */
L_ParticleSystem::init();

// create surface
CL_Surface surface("image.png");
surface.set_alignment(origin_center);

// create a sample of particle with life of 5000
L_Particle particle(&surface,5000);

// create dropping effect with dropping period of 16
L_DroppingEffect effect(0,0,16);

// add the particle to dropper effect
effect.add(&particle);

// initialize particle effect
effect.initialize();


After the effect has been initialized, three basic member functions L_ParticleEffect::trigger(), L_ParticleEffect::run(int) and L_ParticleEffect::draw(int=0,int=0) are needed to be called in order to run and draw the effect. L_ParticleEffect::set_position(int,int) is used to change the position of particle emission, if you change the position continuously every frame, you might get a trailing effect. The following is the code that in main loop.
CL_Display::clear(CL_Color(0,0,0));


// Call L_ParticleEffect::tirgger() to trigger emission of particles
effect.trigger();

// set position of the dropping point
effect.set_position(x_pos, y_pos);

/* pass frame time to L_ParticleEffect::run(int) for time based system,
a constant number would be a reference time unit for frame based system. */
effect.run(16);

// draw dropping effect
effect.draw();


CL_Display::flip();
CL_System::keep_alive();


When you are no longer using LinearParticle, deinitialize it to free resources hold by LinearParticle.
// deinitialize LinearParticle
L_ParticleSystem::deinit();


No fancy effect with this example for getting started, it's recommended to check with the source code of examples that come with LinearParticle to learn using other features.


logo LinearParticle Documentation © 2006-2007 by Wong Chin Foo.
Generated on 8 Jun 2007 by doxygen 1.4.6-NO