For complex things in GameMaker Studio 2 you would normally have an object and then create instances of that object within the room. However, for graphics effects, this can be expensive as every instance comes with a "cost" in processing due to the variables it contains and the codes it has in the different events. You can reduce this cost by turning to tiles for drawing your graphics, or even using the asset layer in the room editor, but both of those are generally only used for drawing simple graphics that maintain the same position over time and have few special effects. However, there is one other option for drawing fast yet versatile graphics effects in your games, and that is to use particles.
Particles are graphic resources with certain properties which are defined within a particle system. These properties cannot be manipulated directly for individual particles, but are changed through the actions that are used to define the individual particle types within the system. They are very useful for creating beautiful and flashy effects (or subtle and discreet ones!) like explosions, decals, rain, snow, star fields and debris in a game without the CPU or GPU overhead that using instances and/or tiles and assets have.
The basic setup for a particle system follows three steps:
Although particles are an excellent tool for creating effects, they do come with certain restrictions and rules of good practice which need to be followed unless you want your game to have issues:
- The particle system, particle types and particle emitters all take up memory and as such you should be very careful how you use them as it is very easy to cause a memory leak which will slow down and eventually crash your game, so each particle type and emitter (and possibly the system itself) should be destroyed the moment it is not needed.
- Particles may be fast and light on the CPU and GPU, but they still require some processing and so you shouldn't have 40,000 of them bursting across the screen at a time. Limit them to those that are necessary to achieve a specific effect and no more.
- If you define your own particle sprite instead of using one of the 14 included sprites, you should try to keep them as small as possible to achieve the effect you require.
- Particles do not interact with anything. Should you need them to have any type of interaction with the user or any other instances in your game, you should be looking at using instances instead as particles are purely graphic.
- Even though there is no technical limit to the amount of emitters and particles you can create in one game, you should try and limit everything to the minimum number possible to keep memory use as low as possible.
- On mobile devices, take care with particles as drawing them can be slow if they cover a large area of the screen (over-draw on mobile devices is one of the main causes of slowdown).
- When targeting the HTML5 platform, note that unless you have WebGL enabled, you cannot have colour blending either (only the first of the particle colours will be used on non-WebGL canvas).
The following sections cover all actions for making your own particle systems:
|Create Particle System|
|Destroy Particle System|
|Clear Particle System|
|Pause Particle System|
|Update Particle System|
|Create Particle Type|
|Destroy Particle Type|
|Set Particle Size|
|Set Particle Sprite|
|Set Particle Shape|
|Set Particle Colour|
|Set Particle Alpha|
|Set Particle Life|
|Set Particle Speed|
|Set Particle Direction|
|Set Particle Orientation|
|Set Particle Gravity|
|Set Secondary Particles|
|Create Particle Emitter|
|Destroy Particle Emitter|
|Set Emitter Region|