Time for action — change depending on the lifetime of a particle

We are now going to introduce more colors by using particle affectors.

  1. We don't want our particle to live 100 seconds for this example, so change the lifetime to 4:
    emitter Point
    {
    emission_rate 30
    direction 1 0 0
    velocity 20
    time_to_live 4
    }
    
  2. Because we want a slightly different behavior, we are going to use the second available colorfader. This should fade each color channel by one unit per second:
    affector ColorFader2
    {
    red1 -1
    green1 -1
    blue1 -1
    
  3. Now, when the particle only has two seconds to live, instead of subtracting the color channel, add the same value we removed beforehand:
    state_change 2
    red2 +1
    green2 +1
    blue2 +1
    }
    
  4. Compile and run the application.
    Time for action — change depending on the lifetime of a particle

What just happened?

We used the ColorFader2 affector. This affector first changed each particle with the given values for red1, green1, and blue1, when the particle only had the number of seconds given as the state_change parameter to live. Values such as red2, green2, and blue2 were used to modify the particles until they died. In this example, we used this affector to first change the particle from white to black and then when it is two seconds away from dying, we changed the black to white, hence creating the effect seen in the preceding image.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.191.34