A simple emitter

Description

Emitters can be created to deal with effects such as engine trails, weapons, smoke and much more. In this program a simple emitter is created that fires particles up into the air.


This example program relies on an external image named "test2.png":

Set up

The code that creates this emitter is as follows:

LoadImage ( 1, "test2.png" )

CreateParticles ( 1, 150, 250 ) SetParticlesImage ( 1, 1 ) SetParticlesStartZone ( 1, -5, 0, 5, 0 ) SetParticlesDirection ( 1, 0, -145 ) SetParticlesAngle ( 1, 15 ) SetParticlesFrequency ( 1, 60 ) SetParticlesLife ( 1, 1.5 ) SetParticlesSize ( 1, 16 ) AddParticlesColorKeyFrame ( 1, 0, 255, 255, 255, 255 ) AddParticlesColorKeyFrame ( 1, 1.5, 255, 255, 255, 0 )

Understanding the code

The code performs the following actions:

Main Loop

Our main loop simply needs to make a call to Sync to update the screen:

do
    Sync ( )
loop

Full code listing

Everything is now in place. Here's the final code for our program:

SetVirtualResolution ( 320, 480 )

CreateSprite ( LoadImage ( "alien_backdrop.jpg" ) )
LoadImage ( 1, "test2.png" )
CreateParticles ( 1, 150, 250 ) SetParticlesImage ( 1, 1 ) SetParticlesStartZone ( 1, -5, 0, 5, 0 ) SetParticlesDirection ( 1, 0, -145 ) SetParticlesAngle ( 1, 15 ) SetParticlesFrequency ( 1, 60 ) SetParticlesLife ( 1, 1.5 ) SetParticlesSize ( 1, 16 ) AddParticlesColorKeyFrame ( 1, 0, 255, 255, 255, 255 ) AddParticlesColorKeyFrame ( 1, 1.5, 255, 255, 255, 0 )
do Sync ( ) loop

Conclusion

With a few lines of code a fairly complex emitter has been generated. This could be used for all kinds of effects such as the exhaust from an engine, poisonous gas escaping from a pipe, smoke and much more.