GameMaker Studio 2: Complete Platformer Tutorial (Part 20: Sparks & Dust)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everybody long time no see today we're gonna be looking at a couple of things it's gonna be pretty simple just to kick us back off I'm getting used to working with the code for this platform Organa the long break but we're gonna look at two things in this episode we're gonna create some hit sparks to the bullet so you can see all I'm hitting the wall some cool hit spark effects are coming out and we're also gonna make some dust effects that you can just see there so when we learned um dust comes out of the player but more importantly than that we're going to learn how you can use a very very simple object event in game maker to create some simple particle effects such as these hopefully it'll fill you with some inspiration and then you can go nuts and create some really cool pretty effects very similar to the ones who created by the end of this I hope you enjoy it let's get started so I gathered and tweaked a couple of little things in between last episode in this episode first off I've added a new level to so just to her Acquia very similar level one really just made some brief changes out of a couple of enemies and just so that we have another level since we lost our previous level - to the room disappearance bug that was going on with Eunice - and it seems you've got the gun because she had to shoot through the crates in level 1 and speaking of the crates I also changed the crates to be 32 by 32 instead of like a 48 by 48 that we did before and just makes it a little bit easier for a few things and just makes it easier to like place them be consistent with kind of my level design on that decided 32 by 32 is just a bit better that's it really I've added a couple new sprites for the things that we're gonna add today this is my hid spark sprite and this is what we're gonna add in first so if I play there seeing as he it's just like a thing where the same shape that's what the bullet is like this shape it's a little bit thinner actually and probably sure to make that a figure but I like it collides and just sort of expands outwards and then disappears and this is just what we're gonna have play a speed of 15 FPS when a bullet hits a wall okay so one way you might imagine of doing this is in our bullet object when we hit a wall changing our sprite to be hit spark and then when the animation ends if we are in that kind of hit spark state we then destroy the object and so on for that raises a couple to do it's slightly more complex to do it that way because you then have to still care about the bullet technically being a bullet object and therefore if anything collides with it while it's in the hit spark animation that might cause a thing that happened and so on so forth so the easiest way we can kind of skip having to care about as many edge cases as possible is to simply make a new object called we'll call it ohit's Park which is warm radio and we're simply gonna turn on bullet into this object when we collide with a wall okay so cold ohit's Park I'm gonna set it to be that sprite that'll be in the description with the zip file as always and what we're gonna do is just create a really simple really lightweight object that just plays this animation and destroys itself and will be automatically positioned wherever our bullet happened to be so really there's a tiny amount of code that we need to actually put in this hit spark object I'm gonna add two events I'm gonna have the create event and I'm gonna add the other animation end event this is a super super useful event I use it all the time we're all kinds of different things and reasons because it just really easily tracks like a fun animation if your current animation has come to an end you can do this otherwise by saying like if image index greater than X or whatever but usually I have a very specific thing I want to happen in animation and then keeping it on an event it's quite nice and so all I want to do is in the create event when this object gets made when the object that's never actually being created from scratch okay ohit's puck is going to be simply the object the oval it turns into when it hits a wall okay it's actually going to change into this object so it's gonna retain most of the properties that the instance of oval at hand so it's X position and its Y position in the room are going to be the same it's image angle and all that nonsense it's all going to be the same so really I just want to overwrite a couple of things from this object and that's gonna be our image index to zero and our image speed to one now those are the default values right any instance of an object created by two or is going to have an image index of zero it's gonna be on its first animation frame it's gonna have a speed of 1 but because we're changing an instance of oh Bella into an instance of ohit's park we are going to retain the image index all over and we're going to retain the image speed of bullets which might be different things depending on what Oberlin is currently doing because we start from that flash and we transition to that bullet and then we stop animating so we want to overwrite these so we set it back to the bank to the default okay and that's all we need to do in the create them an animation and all we're going to do is write instance destroy so what then the animation is over so when those those three frames I showed you before if we go to edit the sprite so when this just comes to an end when it hits that that fourth the blank from we don't even really eat a blank frame and there but we have one anyway when it hits that a frame or sorry when it hits that frame and then animates would would wrap around the animation we just destroy the instance instead this setup just animation and the instance destroy in an object is a really really quick easy dirty way of creating all kinds of wonderful little particle effects and objects themselves are kind of technically a bit heavy and game a coma is they've got a lot built in variables and they have a certain memory footprint and a certain performance footprint especially if you have lots and lots and lots of them but if you're doing things that only show up in small quantities or or or you're just trying to get something in working quickly it can actually just be really effective just to set up an object with very simple behavior that has an animation end instance destroy event okay really really useful we'll be using that for both things that we're gonna add in this video so that's everything we actually needed to add to our head spark as I said it's super lightweight and simple three lines of code so I mean close that now and I'm gonna go up to a bullet now you might remember when we set up over that we used to begin step event to do or collision checking this is to make sure that this happens before our speed is applied although I think the step event would have actually gone away with us as well before our speed is applied so that we can make sure that we actually see the final frame of animation okay because if we applied the speed then check for a collision and destroyed the object all before the the draw happens then we wouldn't actually see our final frame with a bullet like embedded in the ground or embedded in the thing that it hit but we kind of want to do the reverse of that now because we instead of actually wanting to see the bullet on its final frame we want to not see it on this final frame because that's when we want to change it to the hits Park so we don't want to see both at once so we don't actually need it to be that way around anymore this isn't super necessary but just to show you how you can change events from one to the other if you need to to adjust timings and things like that you know right click on begin step and go to change event and go to step and select step and you see that's changed that event from begin step to step but our code is still exactly the same okay really useful in case you will need to change around things like that for timing purposes and all kinds of stuff well I'm gonna do though it's at the moment our bullet is controlled by the speed variable okay so this thing is built-in turns green and it's automatic and an automatic process of an object as let's say objects can be kind of heavy because I've got lots of automatic processes whereby every single frame you've got a speed above zero or below zero or whatever the object is going to move in its direction by that speed amount but the problem is we can't control how or when that happens so I believe by default it happens somewhere between the step event on the end step event but I want to be able to control exactly when it happens so what I'm gonna do is actually going to go to the gun object where we create the ball in the first place in the begin step event here where we set the bullets speed I'm gonna change speed to be SPD so it's gonna be a blue variable that we declare ourselves okay then once I've done that and then I come back to a bullet now by default if I was to load the game and start shooting now our bullets wouldn't move anywhere cuz they never land have the speed set and they just have this SPD thing that doesn't do but at the top here I'm gonna move our object in its direction by its SPD variable rather than a speed so how going to do that how can we replicate that functionality so that has built-in functionality and we're just gonna replicate that in code form it's only two lines of code so we take X plus equal length the in spell length the X SPD comma direction okay and that's it and then Y plus equal when the Y good direction okay and that's absolutely yet so we're moving our X by an amount in a given direction okay and then moving our Y by in certain amount in a certain direction okay hopefully you remember how length there X and length the Y work they returned the specific component so it returns exactly how much in the y coordinate we need to move in order to move X amount in direction okay and how much in the x axis we need to move to move that amount in that direction okay and then both together adds up to moving from one place to another actually really simple stuff cool so that means now we've got complete control over when our speed is applied and we're now applying it before doing all of our clearance so we move the bullet and then check for a collision and then if that collision happens destroying the bullet so we should see now if I run the game what should actually happen is we should see all those disappear a little bit earlier than what they normally would so if I pick up the gun and I shoot well you can see that yeah so it looks a little bit like they're just sort of disappearing a little because they are there more than the hit in the wall that they're moving finding that collision and then being destroyed so we're not seeing that final brain of them anymore which is what we kind of set it up to show us before when we didn't have this his spark that we were going to apply okay so if I close this now what I want to do is here when we collide with a wall instead of just destroying ourselves right away I'm going to open this out into something a little bit bigger and what I'm gonna do is at the bottom here I'm just gonna write insulin we are gonna add more stuff in here eventually that's why I've added those curly braces and a new instance change ohit's spark through okay so what that does is does exactly what you might expect changes our instance from an instance of one particular object which is currently over into an instance of another object which is instance overhead spark so it changes sprite index and all the stuff that comes along with that particular object and then in here you can write perform events and that's whether or not to perform the destroy event of a bullet and the create event of ohit's spark as if you were destroying this object and creating a new one okay so you can put as true or false so I put it as true because we want the create event of ohit's park to run now there is some more stuff gonna put in here but let me just show you exactly how this would look first of all so I have to run the problem we're putting this gun over here knows I don't have to pick it up every time I'm gonna pick up the gun you can see these bullets now have a cool hit spark effect when they get destroyed but the problem is they kind of go into the wall that's a fairly significant shrimp yeah it's because it's just like how fast all that's doing is just they they find a collision but they don't do anything just sort of position themselves at the wall and so on some of the much we look really really spawn there but is just entirely look that's just getting really lucky with where the collision happens to be taking place so how do we fix that well what I'm gonna do is assuming once we found a collision what I'm gonna do is back out of that collision until what right at the edge of the wall okay this is a very simple way it's not gonna look perfect um but it will look a lot better than what we have now so I'm gonna do while place meeting X Y o if you can come up with a quick easy way to improve on the look of what I'm gonna do by the way be sure toast in the comments below that'd be cool to look at the people's uh takes on this kind of thing but what I'm going to do is a quick while loop oh no I'm not gonna while loop instance change bring that out of here we do that afterwards so while we have a collision with the wall which we know we do because we're here in the first place we're gonna move ourselves backwards so remember up here where we this is how we manually move towards our direction we're going to move away from our direction so I'm going to copy this chunk of code paste it in here and just have that a couple of times there we go and instead of moving by speed I'm gonna move by one and I'm gonna change plus equal to minus equal okay so we're gonna subtract this length through X and this length of Y finite which was going to move us in the opposite direction okay I could have also if I wanted to just change this to minus one and kept that as plus but whatever uh-hum quick spelling tip as well while you're doing this is a very very common error I make and it can cause all sorts of wild unpredictable behavior is to have forgotten to change length the like to have written this it takes forever to spot as well when you've accidentally written length to X twice and one need to me length of Y keep an eye out for that cuz I make that mistake all the time it always takes me forever to track it down I'm just like why isn't this doing what I want and it's just that one letter anyway so are you getting up so now so while we have a collision we're going to just move one backwards in the direction we came from okay until there is no longer a collision or no longer in a wall okay you might wonder what's stopping this game an infinite loop well in theory no matter how thick the wall is eventually the wall has an exit right so we should always always come out that's the while loop is reasonably safe I'm also going to change good to be zero which is kind of just a formality really because it doesn't actually do anything in ohit's Park but just in case you know we'll just just be careful and just reset all variables correctly so instance change or two oh yeah all that is correct I think so now if we run a leg game we should see those bullets box go pick up you see they're now pretty much just at the edge one thing with them is obviously they look a bit weird at angles but I mean that's just down to the aesthetic of how you want to draw your hips bug I could write a bunch of code to like do the direction of the Cardinals it's kind of a thing I did in mind and pokey poke but I don't think that works as well with these kind of bullets so I'm just gonna leave it as this now I think it looks okay I think it looks pretty good don't you guys if you actually want this will make it look how it does or change how it looks and so on I think it looks pretty okay cool so hopefully house you've seen from our hits park it's really really cool to be able to write an object with animation and instance destroy to do a cute little effect and it can be used for all kinds of things and I'm gonna demonstrate that with an object I made earlier called owed dust okay so I've got a new sprite up here which is just a white circle that slowly degrades into nothingness and I call it s dust and it's super super useful crowing all kinds of little explosion effects or dust when you land and all kinds of things I'm I I stole this effect than this idea of just doing a simple little object that ends animation and instance destroy from I believe one of Monica or Daniel Winston's LD games because obviously all the source code for those is available I went in how look how he did some things and I know it's the use of this dust object that just done it was a very similar sprite of a white circle it just disappears into nothing let's use animation and instance destroy and I'm like wow you can use that for all kinds of things so I did I started using it as myself and it's really really useful it's really simple an object layout I'll leave the code on screen for a bit you can always pause copy this down but I'll go over it very quickly we've set up an image speed to randomize like how the dust is gonna kind of animate over time so each one is slightly different from the last we also randomize which frame it starts on so by starting from well we can start from like any number of these different sprites and we can vary that as well I'll remember it from three six let's not have that left running from nought to sex so we don't want to that completely skips out with the first three I want to be able to actually use those I'll go from north six hey just bein VSP which we're going to use to move around just round in between -2 and two so that they sort of move in a round of direction by default and then when we create them we can manipulate that image X scale image Y scale so we can also just like choose choose returns a random value out of the values that you provide in the brackets you can provide any number of them as well but I've just given one or minus one so just either flip that one way or the other which will you know either flip it upside down for the right again just add a tiny amount more randomization to how these look and the step event I'm just gonna move them just X plus equal HB y plus equal VSP and have those speeds degrade over time so they move and decelerate so go fast and then slow to a halt okay they'll move er an initial random speed and obviously they'll be animating over time and a semi random speed and when that animation ends destroy the instance and there we go a really simple lightweight dust effect obviously don't want a million of these because as I say objects can get kind of heavy but as a cheaper day in fact it's super super useful super awesome for doing just a little quick particle effects on things if you're doing lots of complex particles you probably want to look into a proper particle like built in particle engine and game maker or at the very least doing some sort of batch drawing thing we use one object to sort of manage the positions and and draw them all at once rather than using an object from each individual particle okay both the quick little distance this can actually be super super useful and works very long-term in the performance impact really isn't all that much so I'm gonna show you a very quick use of this now and then a thing for you guys to go ahead and do is go and think how else you could apply this because there's a million effects that you can apply this to and make it look really good I'm gonna make it happen when the player lands so when they do a jump and when they land I'm gonna Capel out a bunch of little particles so I'm gonna go into the step event for the player I'm gonna scroll right down to the bottom in our animation section we have a handy convenient section here where we've worked out if the player has just landed we needed to do this for our landing sound effect so we can piggyback off of this and I put in some code that's going to create some dust I want to create a bunch of them so I'm gonna use the repeat function you repeat five so everything that we put in these brackets now we're gonna run this section of code five times okay you can put variables in there as well as usual and what I'm gonna do is inter type with instance create a layer we're gonna create this object Oh a syntax errors it's maybe not the way we're going to create this the expedition of X wherever our player is Bbox at bottom this is a new one I don't think I've used so far in this tutorial series where B box a stands for bounding box that case of the collision box of the player B box bottom returns the bottom of that collision box there's also be box left B box top and B box right returns those coordinates so left and right give you the x coordinates of the left and right bottom and top give you the Y coordinates of the top and bomb of your collision box are really really handy for doing lots of different things I believe it calculates them every time it's called I could be wrong about that so if you're gonna use it a lot in an event it's worth putting it into a variable but I just usually hit the ones here so it's not too bad the layer we're just gonna put it on the bullets layer why not it's probably a bit lazy we should probably make which probably refactor the layers at some point in this but uh it'll do for now we'll put it on the bullets layout we'll call it the object we're gonna make is a s okay and we've done a width with the ID of the instance that this has created okay so with that object that we've just created I'm gonna side vs p equals zero because we're we're gonna land on the floor I'm gonna want there just to spread out kind of sideways from the player and since it has a random horizontal speed in books P already it'll do that but whatever random vertical speed we have I'm going to set it to zero so it doesn't go up or down okay and that's really all there is to it so if I run the game now we should see it right away as well we'll just when I when I land you see this dust popping out the player now really nice little subtle effect and it's randomized a nice as well so it looks kind of cool it's one little thing you might want to look into it this is obviously now and again even though there's five there's five of them so most of the time they're going to get a nice spread left and right but now and again you might get all five going to the right or all five going for the left might be worth looking into how you could use the width statement we've used here to manipulate that in such a way so that we always get an even spread of left and right if you think about that and think about all the code you blend you might work out a way you can do that or you might just like it like fully randomized so there's other things you could do here you could create one for when you jump you could try that you could create it for when you walk just every now and again every few steps kicking off a bit of dust I'll leave you to experiment with that it's really really useful in fact you can use it for when things explode you can make bigger ones and so on do whatever you like anyway I hope this has been useful for you hope you've hope that gives you some inspiration on how many can use really lightweight particle style objects to do some really cool effects and I'll catch you guys on the next part thank you very much for watching see you guys next time thank you all very much your patients over the last few weeks I know there haven't been that many videos I've had a lot of different things going on but we are now back into the full swing of things thank you especially as always to all of my patreon supporters without whom none of these videos could exist and a super special shout out in particular to the following mark Clint's Dan run James Crumm we mark day Cody Hodkinson Adam Rove and Alan Harold Guidry welp matte coat Sam stallion Lewis our Pereira Nix lavish Steven Hagen Michael Ward Jason McMillan Edward laco Shana --then Robert churches Owen Morgan Zenon a turtle time boughs of the dog TJ Marcel Joshua gazenga and Patrick Duffy thank you all so much for your support and I'll catch you all next time
Info
Channel: Shaun Spalding
Views: 50,867
Rating: undefined out of 5
Keywords: Game Maker (Video Game Engine), Tutorial, GameMaker Tutorial, GameMaker, Game Development, Indie Games, Tutorial Series, Game Maker Studio, Making Games, How to make games, GameMaker Studio 2, GMS, GMS2
Id: 6EJzYfmmH9w
Channel Id: undefined
Length: 24min 1sec (1441 seconds)
Published: Fri Jun 15 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.