Gamemaker DND Platformer Tutorial - #12 Screen Shake

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
if you're interested in making a detailed platformer just like this one with in game maker using drag-and-drop then keep watching [Music] g'day gamers and welcome back to our drag-and-drop platformer series in the last tutorial we added some juice effects to make our game feel better in this tutorial we're going to add a screen shake effect and what that'll do is just make the impacts with the enemies a little bit more powerful and also you can use it in other aspects of your game so when we jump on the enemies head we've little shake happening and the screen shakes just to show how powerful the impact was it's a great effect and it's used in many games now in order to make it appear like the screen is shaking what we want to do is actually change what we're seeing by small amounts each step and that'll make it appear like the screen is shaking now what we see in game maker is being viewed through the viewport so we need to change the viewport every step by only a small amount and that'll make it appear like the screen is shaking now I'm going to serve some variables in the old game object so let's go to our game let's go to our variable definition let's add some variables here for our screen shake and the first one is going to be called screen shake and this is going to be a boolean and a boolean means it's either true or false so we'll enable it and set it to true when we want the screen to shake and we'll just set it to false when we want it to stop I'm going to add another variable and this one is going to be called shake amount or shake underscore amount now shake amount is going to be how much the screen shakes or how many pixels it moves per step I'm going to set it at 3 and I'm going to have a shake time and that is obviously how long the screen shake will go for now to set it for 15 and that'll be 15 steps but with our game running at 60 frames a second and a shake time of 15 that is 15 over 60 which is 1/4 of a second Annelle let's go to the step event of our game and we can close this and just clean it up a bit to make it easier to see so it can close this down and that's our code for a background scrolling you also notice there's a small section here which actually have been disabled you can right-click and you can disable or enable code blocks I've disabled these but these are the code blocks that would be used to replace this section here and someone had asked in a previous parallax scrolling tutorial if they could do all of this in code now I did it in code and I added it as a screenshot into the comment section of the parallax scrolling but I've disabled it in here and just so show it to you in case you want to change yours you can use code blocks for that as well I'm going to leave it there as it's a handy reference so now let's add the screen shake code so what we want to do is say if our screen shake is active then we want to do something to the viewport so let's grab an if variable block I might we can just close these up Isis down here look at our screen shake variable and say if our screen shake variable is equal to true then we want to enable our screen shake now we also need to make sure that it only goes for the length of our shake time and we can do that with a timer now game maker has alarms which are used as timers and they will countdown each step so that you can set things to happen after a certain amount of time so if our screen shake variable is set to true then we want to go in and set our alarm we got here under set alarm countdown and we'll just use alarm zero we want to set it to our shake time that'll set our timer now if you type up here you type view you'll get a camera option and one of them is to set the view variable we want to change the view and we're going to change the view x-coordinate now our view is just a zero because we don't use any other views than that one and we want to set it to a value and it's going to be a random value so I'm going to say random underscore range IFS will be a random number between two numbers now we set a shake amount variable so I want it to be set between - shake them out amar and positive shake amount we'll get a number between negative I think of three we said of that and three we wanted to copy and paste that because we want the same thing but we want it for the y coordinate now if we have a look at what's happening here if our screen shake variable is true we're setting our alarm and then we're changing our view by a small amount each step now the problem with this is the alarm is being set every step and it never gets a chance to countdown because it's being reset to shake time every step but we only want to set the alarm countdown to shake time the first time we come into the screen shake section so we can do that by saying that the first time we come in the alarm is actually already zero if it's already zero then we want to set it let's go and have another check here say that if our alarm zero and you can write it this way is less than I'm going to say less than or equal to zero then we want to set it and that way it'll happen only once the first time we come in here and now we need to create this alarm zero so under events go to alarm go to zero and inside here we can turn off the screen shake because it'll countdown when it gets to zero the code in here will then run so we can just assign a variable and we want to assign our screen shake variable to be a value of false all that's left is to call our screen shake when we want to apply it let's go to our player let's go to our collision with the enemy and in here we can apply a screen shake when we jump on the enemy's head and we're looking for the part where we jump on the head and that's just here so this section in here we're applying the explosion and we're setting the enemy state to dead and the bottom here let's get an apply to let's apply it to our game object that a variable within our game and we're going to set screen shake to be true try that out now when we jump on the head we get a little shake happening now it's very minor but you can change the variables if you want anything larger just under a game definitions the amount here is indicating how large you want the screen check to be there you can change this if you want it to be larger so let's say something like 4 or even 5 and you'll get a larger amount and you can also change the time if you like and we get a little bit of a larger explosion now the other thing is that you can go into here and you can set those variables at this time as well but you're calling a screen shake from other objects and you want it to be longer or larger you can just modify it by setting a variable here as well and you would change say Shake amount and then set it to another value and that way you can have different shake amounts for different events now ideally you would want to put the call to the screen shake into a script and you pass the amount and the time at that time but that's a little bit more complicated then what I want to do for this tutorial but it might be something you want to work on and try it yourself that's all for this tutorial in my udemy course I actually work more on the screen shake and we make it into a little script that you can call with a single line that changes the shake amount and the time very easily the course is currently the highest rated game maker to course on udemy there's a coupon code in the description I suggest you check it out because if you're interested in game maker it's getting really good reviews and people are very excited about learning from their course if that's not something you're interested in but you are interested in supporting the work that I'm doing here you can head over to my patreon account and show your support that way there's a link for that in the description as well thanks for joining me I look forward to seeing you in the next one [Music]
Info
Channel: Slyddar
Views: 4,027
Rating: undefined out of 5
Keywords: gamemaker, drag and drop, dnd, collision, platformer, platform, make game, jump on head, enemy ai, gms2, drag n drop, drag, drop, dragndrop, tutorial, peter morgan, one way, oneway, fall, make games, shaun spalding, heartbeast, spalding, yoyo, gms, advanced, learn, vertical, parallax background, parallax, enemy, damage, kill, hurt, mario, jump, damage player, dead state, dust, fx, effects, juice, screen shake, screenshake
Id: RpgNL_BafM0
Channel Id: undefined
Length: 9min 48sec (588 seconds)
Published: Sun Sep 08 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.