There are a number of different functions that can be used to define a particle effect, which we'll list and explain below, before showing a snippet of code that has them all together, as they should be used: We have a particle type created, but we still have to define its general properties (ie: how it looks, its speed, rotation, alpha etc.). We'll explain what enabling this means a bit further along in this article. Let's name and add our first particle to the system (the following code would go in the Room Start event of the same object we used to create the particle system):īefore continuing, note that the DnD™ action permits you to enable or disable additive blending for the particle when it is drawn to the screen. What this means is that if you give the particles a minimum movement speed of 1 and a maximum movement speed of 2, any particle created by the system will have a random speed between 1 and 2 pixels per step, and that overall they will have an average speed of 1.5. These are like object properties, but they only apply in a general way to individual particles. That's the system created then, but what about the particles? We have to define them too or the system is useless and does nothing! To create a particle, you have to define its general properties. If you set this to false, then trying to access the system using the global variable will cause an error. This is because we want it to persist across all rooms without having to recreate it again. Note that we also flag the system as persistent. It's good practice to create a layer specifically for the particle system and then place your controller instance on that (or assign the layer when you create the system). In the code above we are assigning it to the layer that the instance running the code is on, but you could as easily give it to any layer present in the room, that the controller instance will be placed in. Notice that the particle system is given a layer. Global.P_System=part_system_create_layer(layer, true) Since this is going to be a global system that any object can use we will set it up like this: This particle controller object would be placed in the first room of your game and the following code should be placed in the Game Start event. To start with, we'll need a controller object for the particle system and then in that, we need to define the system properties and give it a name so that we can use it later. So, in this tech blog, we will make a global particle system that can be used by any object at any time. This is because a particle system, once created, stays in memory and is ready to be used at any time, so if you create it more than once it can quickly increase the memory usage and eventually cause serious lag or even crashing the game. HOW DO I SET ONE UP?īefore setting up a particle system it's important to note that most of a particle systems code is only ever called once in a game, usually in some type of controller object in the first room or level (this is not always the case, but it is a general rule of thumb).
#How to use game maker studio 2 series
We use code to define a series of visual aspects for our particle, and then we place it in the "container" so that we can take it out and use it whenever and wherever we need later. Think of a particle system like a container that we will use to hold our particles ready for use. Fire effect made with particles, courtesy of Martin Crownover