Feuer

Now that we have the right bitmap, we can start with programming. Like always, we will start with the emitter action.

We can use the emitter function from the basics tutorial as a template, but we will have to make some modifications.
An important thing to remember is that our effect has to look the same at a high framerate as at a low one. At 75fps, our basic emitter action would emit 3 times as many particles in a given timeframe as at 25fps. So the look of our fire would completely vary. (particle lifetime and speeds are not framerate dependent - the fire would be much brighter and 'thicker' at a high framerate)

To eliminate this effect, we introduce a counter into our action that is initialised incorporating the system-variable TIME.  (TIME is directly framerate dependent)
We decrease the counter value until it reaches 0, then we emit our particles and re-initialise the counter. In order to make 'hot fires' possible, we emit 2 particles at once, emitting only a single particle at each initialisation would produce too few particles.

We will also include skill8 into the initialisation formula, since we want to be able to control the intensity of our fire by setting and altering skill values.
This directly leads us to the formula 'my.skill13 = my.skill8 / TIME;' for the counter initialisation; if TIME has low values (high framerate) skill13 is initialised with higher starting values and vice versa.

Since we don't want our particles to be created at the same spot each time, we variate the starting positions on the x and y axis with a random value and then store them in the skills 10, 11 und 12 (x,y,z). These three skills are used as the position vector in the emit function.

Here is the complete emitter action:

action particle1{
    while(1) {                                               // fire burns forever
        my.skill13 -= 1;                                  // counter is decreased
        if (my.skill13 <= 0) {                            // if the counter reaches 0:
            my.skill13 = my.skill8 / TIME;          // reinitialise counter
            my.skill10 = my.x + random(4) - 2;   // vary and store pos.x
            my.skill11 = my.y + random(4) - 2;   // vary and store pos.y
            my.skill12 = my.z;                          // store pos.z
            emit(1,my.skill10,test_particle1);      // create particle
            my.skill10 = my.x + random(4) - 2;   // vary and store second pos.x
            my.skill11 = my.y + random(4) - 2;   // vary and store second pos.y
            emit(1,my.skill10,test_particle1);      // create second particle
        }
    wait(1);                                                   // we don't like the 'endless loop' error message
    }
}

next page >>