Particle systems

Game Maker 8

Particle systems

Particles live in particle systems. So to have particles in your game you need to create one or more particle systems. There can be different particle systems (but preferably keep their number small). For example, if your game has a number of balls and each ball should have a tail of particles, most likely each ball has its own particle system. The easiest way to deal with particle systems is to create one and then create particles in it, using the particle types you specified before. But, as we will see below, particle systems can contain emitters that automatically produce particles, attractors that attract them, and destroyers that destroy them.

Once particles are added to a particle system they are automatically updated each step and drawn. No further action is required. To make it possible that particles are drawn, behind, in front of, or between object instances, each particle system has a depth, similar to instances and tiles.

Particle systems will live on forever after they are created. So even if you change room or restart the game, the systems and the particles remain. So you better make sure you destroy them once you no longer need them.

The following basic functions deal with particle systems:

part_system_create() Creates a new particle system. It returns the index of the system. This index must be used in all calls below to set the properties of the particle system.
part_system_destroy(ind) Destroys the particle system ind. Call this if you don't need it anymore to save space.
part_system_exists(ind) Returns whether the indicated particle system exists.
part_system_clear(ind) Clears the particle system ind to its default settings, removing all particles and emitter and attractors in it.
part_system_draw_order(ind,oldtonew) Sets the order in which the particle system draws the particles. When oldtonew is true the oldest particles are drawn first and the newer one lie on top of them (default). Otherwise the newest particles are drawn first. This can give rather different effects.
part_system_depth(ind,depth) Sets the depth of the particle system. This can be used to let the particles appear behind, in front of, or in between instances.
part_system_position(ind,x,y) Sets the position where the particle system is drawn. This is normally not necessary but if you want to have particles at a position relative to a moving object, you can set the position e.g. to that object.

As indicated above, the particle system is automatically updated and drawn. But sometimes this is not what you want. To facilitate this, you can switch off automatic updating or drawing and then decide yourself when to update or draw the particle system. For this you can use the following functions:

part_system_automatic_update(ind,automatic) Indicates whether the particle system must be updated automatically (1) or not (0). Default is 1.
part_system_automatic_draw(ind,automatic) Indicates whether the particle system must be drawn automatically (1) or not (0). Default is 1.
part_system_update(ind) This functions updates the position of all particles in the system and lets the emitters create particles. You only have to call this when updating is not automatic. (Although sometimes it is also useful to call this function a couple of time to get the system going.)
part_system_drawit(ind) This functions draws the particles in the system. You only have to call this when drawing is not automatic. It should be called in the draw event of some object.

The following functions deal with particles in a particle systems:

part_particles_create(ind,x,y,parttype,number) This functions creates number particles of the indicated type at postion (x,y) in the system.
part_particles_create_color(ind,x,y,parttype,color,number) This functions creates number particles of the indicated type at postion (x,y) in the system with the indicated color. This is only useful when the particle type defines a single color (or does not define a color at all).
part_particles_clear(ind) This functions removes all particles in the system.
part_particles_count(ind) This functions returns the number of particles in the system.