PARTICLES in GMS2 -- GameMaker Tutorial (Introduction to Particle Effects)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey there in this video we'll be learning about particles here's a preview of what we'll be making in this video now I have this empty project here to start I'm gonna create a new object called a game controller so if you have a game controller present in your game rooms you can use that for your in-game particles I'm gonna drop this into the room and then I'll go back to the object here I'm gonna add the create event I'm gonna create a particle system here in this variable for that I'm gonna use this function now a particle system is where your particles are created so you need a particle system to create any particles so this will be have a particle system for this video now you can also specify a depth for your particle system so all the particles in that system will be drawn at that depth so to set a depth value I'm gonna use this function I can pass in the particle system and then the depth value so I'm gonna set this to minus 100 now you can also use part system create layer to create a particle system directly on a layer in the room now when the game room ends and the game controller is gone we want the particle system to be destroyed for that we can I use the cleanup event here I'll simply destroy in a particle system using dysfunction now to actually create particles in this particle system we need a particle type so for each different type of particle you need a particle type I like to create my particle types in a script that runs when the game starts so I'll create a new script for that and I'll name it in it now in the script we want to make sure that it runs when the game starts so for that I'll add does we are honoring the GML pragma function to give a command to the compiler that command is global using the global command we can run some code when the game starts so that code is in there string in the code we are simply running the init script so this way this script will run when the game starts now if you're in the future and you have game maker studio 2.3 or above then you don't need to do this anything you put in the script will automatically run when the game starts just don't put it in a function not for creating our particle types I'm gonna create a new region I'm gonna end it vendors so now we have a region that we can close and open now I'm gonna create a basic particle the variable for this particle type will be global PD basic to create the particle type I can use this function so this way we have now created an empty particle type bar instead of storing it in a global variable directly I'm gonna use a local variable first and then we can simply assign the particle type from the local variable to the global variable now the reason why I am doing this is because this is easier to type than this so when setting up the particle type we can simply use this variable instead of this so for the particle type properties we are not gonna learn about the shape and life the shape is simply when the particle will look like sawdust and the shape we can use this function first we pass in the particle side which is in the local variable and then we specify the shape so these are under the PD shape constants if you type that you can see all of the shapes in the list I'm gonna select the desk one and then I'll middle click on the constant this will open the manual where we can see all the shapes so this is the one we are selected now I'll close the manual and back in the script I'll finish the function call so this way we have specified when the particle looks like and now we are gonna give it a life the life of a particle is how long it stays on screen so to set the life we use this function in the arguments we have a minimum value and a maximum value Saudi actual life of the particle will be random between these two values Sol's had the minimum to 20 steps and the maximum to 40 steps so now the actual life of the particle will be random between 20 steps and 40 steps now we are gonna create this particle type in our particle system so in the game controller object I'll add the step event I want to create the particle wherever I press the mouse so I'll add this this checks if the mouse button is held down in that case we are creating our particle type so this is the function we use for that here we pass in the particle system that we are using then we have the position where the particle will be created so that will simply be the mouse x and y the particle will be created wherever the mouse is then we have the particle type that will be created so we pass in the global PD basic particle then finally we have the count this is how many particles will be created with this function call we only need one per cell so this should create our particle I'll go in the game and when I click a particle will be created it has a disk shape and its life is random between 20 and 40 steps now we can start animating our particle so we're gonna learn about D alpha color and size properties for the Alpha I'm gonna write this now in the list you can see we have three functions we have alpha 1 alpha 2 and alpha 3 with alpha 1 we can simply say an alpha value for the particle now alpha 2 is what allows you to animate the Alpha you pass in two alpha values one for the beginning and one for the ending than with alpha 3 we have the alpha value in the beginning then in the middle and then in the end I'm gonna use the Alpha to function and pass in the particle type now for the first alpha value I'll enter one and then for the second alpha value Alan to zero so the Alpha will be one in the beginning and by the end it will be zero so now in the game you can see the effect the particles now have a fading effect I'm now gonna show you what happens when you use the alpha 3 function so for the Alpha values in this function we have start middle and end I'm gonna set the start value to zero so now the alpha for this particle will go from 0 to 1 to 0 so I'll run the game now and create a particle and you will see the Alpha go from 0 to 1 and then back to 0 so we have different ways of animating the Alpha of a particle now in the script I'm gonna change the alpha back to the Alpha 2 function and the values will again be 1 and 0 now we'll be looking into changing the color of a particle so I'll type this for the color and here you can see that we have color one color 2 and color 3 functions and just like we did for the Alpha so like the Alpha functions they allow you to animate the color values so I'll use the color to function for the starting color all until see red and for the ending color all until C white I think you know what's gonna happen now the particles will start red and then they'll fade into white so this makes a really nice particle effect because the color is not constant now we can also change and animate the size of the particle for that we can use the bar type size function now in the arguments we have sighs minimum size maximum size increase and size bigger now the starting size of a particle will be random between the minimum and the maximum soil until 0.74 the minimum and 1/4 the maximum the size of the particle will be random between 0.7 and 1 and 1 is the full size of the particle now the next argument is the increased value any value you enter here will be added to the size of the particle every step so you can make the particle grow or even shrink by entering a negative value for now I'll leave this at 0 the next argument now is size wiggle any value entered here will be randomly added or subtracted from the size this way you can make your animation a little erratic I'll leave this at 0 and now I'll run the game now when I create the particles some will be smaller than others so the size of each particle is random between 0.7 and 1 now you're gonna make our particle grow so for the size range in this function I'll enter zero point one and zero point two so the particle will start small then in the increase argument I'll enter 0.025 so this will be added to the size of the particle every step I'll go into the game now and the particles now grow from a smaller size so this way you can animate the size of a particle now we'll be learning about the speed direction and gravity properties you can use these properties to make the particles move in any direction first we can a set the speed so for that we use this function in the arguments we have a minimum speed in maximum speed and increased value and a vehicle value so these are the same arguments we had in the size function I'm gonna set the minimum to two and the maximum to four so the actual speed of the particle will be random between two and four and then I'll set the increase and avigal to zero so in the game the particles are now moving because we set the speed but they are moving only to the right this is because the default direction is zero and zero points to the right so we are now going to set a direction for the particle for that we use this function now the arguments here are the same as before so we have minimum maximum increase and because now I want to make the particles go up so the direction value for that is 90 but I also want there to be some variation in the direction so to achieve that I'll enter 80 in the minimum and hundred in the maximum then for the increase and the wiggle I'll enter zero so the direction can be anywhere between 80 and 100 and that's what we get in the game the particles are now going up now I'm gonna modify the direction all set the minimum to zero and the maximum to 360 this way the particle can go in any direction and that's what happens in the game the particles are just moving in random directions now we'll be adding gravity to the particle for adding gravity we use dysfunction in the argument we simply have the speed of the gravity and the direction for the speed Allen 20.2 and for the direction Allen to 270 270 points downwards and now our particles have gravity you can feel that they have a weight now now we'll be learning about the sprite and orientation properties I've imported this animation that I want to use for my particles currently we are defining our particles appearance with a built in shape so I'm gonna remove the shape function then I'll also remove the Alpha color and size and then finally I'll remove the gravity so now this is a simple particle that has a life a speed and a direction now instead of a shape I'm gonna use a sprite for this particle so up here I'm gonna use this function with this we can simply assign a sprite to the particle I'm gonna bring up the arguments now and the next argument we have here is the sprite so for that are simply pass in as fireball now the next argument tells whether the sprite should be animated or not I don't want it to animate for now so I'll set it to false now the next argument is stretch if you set this to true then the animation of the sprite will be stretched to fit the life of the particle but we are not animating the sprite so I'll just set this to false now the last argument here is random if this is true then the starting sub image of the sprite animation will be random I'm gonna set this to false now I'll go into the game and you can see that our particle is a fireball but you can see that the particle doesn't rotate at all so this is where the orientation comes in the orientation is simply the image angle of a particle so for the orientation we have this function if you look at the arguments we again have minimum maximum increase and we go I'm gonna set all of these to zero because I don't want to make the orientation something specific or something random I just want it to be relative to the direction so for that I can use this last argument I'll set it to true display the image angle of a particle will be relative to its direction if I run the game now the particles will face where they are moving now the particle start big so it looks odd in the beginning so to the particle I'm gonna add the size property the range for the size will be 0 and 0 and it will increase by 0.04 so this way the particle should grow from nothing and when I go into the game that's what happens now we'll be animating the sprite in the sprite function we have disagreements for animation if I set this to true then the sprite will animate now I'll go into the game and create some particles and they don't exactly look good this is happening simply because the animation doesn't fit the life of the particle in our case the animation is actually shorter than the particles life so to make it fit we can use the stretch argument so I'll set this to true and then run the game again and now the animation plays fine now we'll be learning about step particles this is how you make one particle type create another particle type first for our basic particle I'm gonna remove the sprite function I'm gonna give it a shape and the shape for this particle will be the disk shape now I'll also set the scale of this particle with this function now this function is different from the size function this allows you to animate the overall size of the particle but the scale function is not for animation it simply allows you to set the X scale and the Y scale of the particle so I'll set both arguments to 0.3 now you can use to scale with the size without any problems but I'm gonna remove the size for this particle so in the game the particles now look like this if you're gonna give this particle a trail which will look like this so now at the bottom of the region I'm gonna add this here we are creating a new particle type so we are using the same local variable to store the ID of the new particle type we are giving God a shape and that shape a circle and here's what that shape looks like then we are giving it alive and that can be between 40 and 50 steps and then we are giving here a size property the starting size will be 0.4 an each step and this will be added to the size since it is a negative value the particle will shrink now we store that particle type in global PT trail now we want the basic particle to create this trail particle every step so for that we use this function here we pass in the base particle that we are modifying so that's global PD basic then this is how many particles will be created every step so I've set that to 1 and this is the particle type that will be created so we are creating the trail particle once per step on the basic particle so I'll go into the game and now our basic particle has a trail now I'll go back to the trail particle to the size function here I'm gonna set the last argument which is a bigger value to 0.05 this will be randomly added or subtracted from the size every step if you go into the game now the trail looks much better especially compared to before now we are gonna learn about death particles kind of what not name but they are very useful when a particle dies we can have it create another particle so like an explosion or something so we're gonna do exactly that and for that at the end of the region I'm gonna add this here we are creating a new particle type which will appear when the basic particle dives for this particle the shape is set to flare so here's what that looks like then the life is said to be between 30 and 40 now for the size I've said the minimum and the maximum to 0.3 and 0.4 then it's also gonna grow by 0.08 every step now for the Alpha I'm using the alpha 3 function so the Alpha for this particle will go from 0 point 8 to 1 and then to 0 now I save that particle in global bTW death explosion and then we set it as the death particle for the global PD basic particle so when this particle dies this particle will be created and of course this is the count of how many particles will be created so now when the basic particle dies an explosion particle will be created now to make the explosion look better we can enable additive blending in this way the color values of the particle will be directly added to the background to make it look brighter so for that we can use this function by simply setting it to true we can enable additive blending for the particle so now the explosions look much better especially if you compare them to the previous ones now with step particles and death particles you saw how you can make particles create their own particles and this can be used for some nice effects if you want to know how to create a specific particle effect drop it down in the comments if I have enough suggestions I may do a video on that for now you can check out my other videos to catch my future ones make sure to subscribe here and I'll see you in the next one
Info
Channel: GameMakerStation - Matharoo
Views: 11,882
Rating: undefined out of 5
Keywords: gms, gamemaker, gamemaker studio, gamemaker studio 2, game maker 2, gamemaker 2, gm2, gm 2, gms 2, gms2, tutorial, particle, particles, effects, systems, particle types, graphics, graphic
Id: tV4ghL4CEtw
Channel Id: undefined
Length: 19min 44sec (1184 seconds)
Published: Sat Apr 18 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.