This tutorial expands on the Hero ’ south Trail project provided with GameMaker. We ’ ll add all sorts of sound effects to the game, learn how to change the music, program a pause menu screen and a new help screen that shows the controls !
This tutorial has the keep up sections :
Let ‘s beginning look at how sound effects can be played using GML Visual !
sound effects and music tracks are added as sound assets in the Asset Browser, which can then be played using the “Play
Audio” action :
What do the three options do ?
- “ Sound” : This is the reasoned asset that we want to play. You can either enter the identify of the sound asset that you want to play, or click on the button to choose an asset from the Asset Explorer.
- “ Loop” : This controls whether the sound should replay after it has ended. This is useful for music loops, as you can enable this to keep them playing constantly ; however it should be disabled for voice effects as they should only play once for each action.
- “ Target” : If you specify a variable name here, that variable will store the unique ID of the sound that was played. You by and large won ’ t need this unless you want to change the properties for that sound ( like flip and volume ) .
Let ’ s practice this to implement strait effects for the assorted mechanics in our game !
If your game does not have some of the features listed in this tutorial ( i.e. bats, pickups, sequences ), read the Features Index page to follow those tutorials .
We ’ ll first play the phone for when the player picks up a coin :
- Go to obj_coin and open its collision consequence with obj_player.
- This consequence runs when the player touches the mint.
- Add the “Play Audio” action and use it to play the snd_coin sound.
- This sound can be found under “Sounds” – > “Items” .
Power Ups / Pickups
Let ’ s now play a sound for our world power ups and pickups, starting with the heart pickup :
- Go to obj_player and open its collision event with obj_heart_pickup.
- here, play the snd_powerup good ( under “Sounds” – > “Items” ). Make sure to attach it to the chief condition .
You can now play the same sound for the collision events with obj_powerup_speed and obj_powerup_star .
here are some other pickup sounds you can implement — assets for these are already show in the project :
- snd_key : This should play when the winder is collected by the player ( hint : there is a collision consequence in the obj_key object )
Let ’ s play a phone when the player swings the sword :
- Go to obj_player and open its “Key Press – Space” consequence.
- At the end of the event, play the snd_sword_swing reasoned.
- This sound is present under “Sounds” – > “Characters” .
here are some other sounds you can implement – assets for these are already stage in the project besides :
- snd_lever_pull : Play this when the player interacts with the pry ( hint : this happens in a collision event in the obj_lever object )
- snd_finish_level : Play this when the musician finishes the level ( tip : see the obj_next_level object )
- snd_player_defeated : Play this when the actor runs out of all hearts and is defeated ( look at Alarm 0 in obj_player, or add a Create event to the obj_player_defeated object )
You can besides play a sound in a Sequence, so let ’ s do that for our “ villain defeated ” sequence :
- In the Asset Browser, find the seq_baddie_defeated Sequence and open it.
- Make sure your playhead is on the first frame .
- In the Asset Browser again, go under “Sounds”, then “Characters” and find the snd_baddie_defeated sound.
- Drag that sound into the Track Panel of the Sequence.
- You can now change when the heavy plays by moving its asset key on the Dope Sheet .
The Sequence will now play with the audio when a villain is defeated !
We ’ ll now play a iteration voice for the bat flapping its wings. Let ’ s do the follow :
- Go to obj_bat and add the Create event.
- here, play the snd_bat_fly sound with looping enabled. We ’ ll store its ID in a varying called fly_sound so we can stop this specific fathom late.
- This strait can be found under “Sounds” – > “Characters” .
- The variable should not be impermanent, as we will later need to access it in a unlike consequence .
Let ’ s stop this sound when the bat no longer exists :
- Add the Clean Up event to the bat object.
- This consequence runs when the exemplify stops existing .
- here, use “Stop Audio” to stop the bat ’ s fly sound — enter the varying that was created in the Create event ( fly_sound ) .
Note : Lower your volume now as the sound of all bats will be loud. We will work further on this in the next section.
If you run the bet on, you will hear the bats flapping their wings, however there is one boastfully trouble : you ’ re able to hear all the bats in the flush at once ! Let ‘s make it so you can only hear those near you .
ideally, the strait from an object should only play when the musician is near it, and should fade away as the player walks off from it. This is implemented into the base project with the foe, fountains and the torches, and now we ’ ll add that have ourselves to the bat .
For this, we ‘ll need to learn what functions are .
A function is similar to an action, as it takes a certain number of inputs and performs an action. There are a huge numeral of functions available in GameMaker that can be used with the “Function Call” action :
here ’ s what each playing field in this natural process means :
- “ Function” : This is the diagnose of the function that we ’ rhenium calling ( or using ).
- “ Argument” : This is merely an option that is passed into the officiate. You can press the plus push button on the left to add another argument, if the serve requires it.
- “ Target” : This is the name of the variable that stores the resultant role of the function. You can make it irregular by enabling the “Temp” option .
We ’ ll now use a function to implement our “ proximity audio ” feature .
We ’ re already playing the bat ’ mho sound in its object, so we plainly need to find its distance from the player, and change the volume of its sound consequently. The close the player is, the forte the legal will be .
Let ’ s do the follow :
- Go to obj_bat and open the End Step event. We ’ ra using end step as it runs after all instances have moved.
- here, add the “If Instance Exists” action ( this is a condition ) and check if obj_player exists. We ’ rhenium doing this to make sure the main player aim is active ( and not the get the better of one ).
- Attach a “Function Call” natural process to the stipulate and use it to call the point_distance serve. This routine calculates the distance between two points.
- It takes four arguments : the first two are the coordinates of the first point, and the last two are the coordinates of the second
- Our first point will be the bat ‘s own position ( merely x and y ) and the second point will be the player ‘s place ( obj_player.x and obj_player.y ) .
- You need to add three more argument fields by clicking on the summation push button .
- This distance will be stored in a impermanent variable called distance .
- After that, use the “Set Audio Volume” action to change the volume of the bat ’ s fly_sound to 50 / distance. This means that the sound will play at full volume when the bat is precisely 50 pixels away from the player, and after that it will get faint .
Use the follow settings for the new actions :
Run the game now, and you will notice that the bat sounds can ’ triiodothyronine be heard anymore. You will only hear it if you go near a bat, which is precisely what we wanted !
here is another bat sound that you can play :
- snd_bat_shoot : Play this when a bot shoots ( hint : Do that in its Alarm 0 event ) .
- snd_bat_defeat : Play this when the bat stops existing ( trace : Do that in the collision consequence with the sword ) .
And here are some other features that besides need healthy effects ( the sounds for these are besides introduce in the project ) :
- Chests. You can play snd_chest_locked when the player tries to open a locked chest, and snd_chest_open when it actually opens.
- Energy Shield. You can play snd_shield_activate in the shield object’s Create event, and snd_shield_deactivate in its Clean Up event.
- You can also play snd_shield_loop with looping enabled when the shield is created, and stop it when the shield is removed.
- Gates. You can play snd_gate_iron_open when the lever is pulled and the gate opens.
We ’ rhenium now going to switch the crippled music to another cut ( snd_music_rampage ) while the indomitability ability up is active. After the power up is over, the music will switch back to the regular track ( snd_music_game ) .
hera ’ s how we ’ ll play the rampage track :
- Go to obj_player and open its collision event with obj_powerup_invinc.
- This event runs when the player collects an indomitability baron up, and we ’ ll change the music track here.
- first add a “Pause Audio” action and use this to pause the game music ( snd_music_game ).
- then add a “Play Audio” military action and use this to play the rampage music ( snd_music_rampage ). Make sure to enable looping .
This will now switch the music from the plot track to the rampage track when you collect the indomitability exponent up. Let ’ s now handle how the music will switch bet on once the power up is over :
- Open the Alarm 1 event of the actor object, which handles deactivating a office up.
- here, add the “If Audio Is Playing” action to check if snd_music_rampage is playing.
- If it is, use “Stop Audio” to stop that track ( attach it to the circumstance ).
- then add the “If Audio Is Paused” action to check if snd_music_game is paused.
- If it is, function “Resume Audio” to resume the game track ( attach it to the condition ) .
here is how your new actions should look :
This will stop the rampage music if it’s playing, and resume the plot music if it’s paused. now run the game and collect the star topology ability up. You will hear the music change, and after the world power up is over, the game will switch back to the old track .
Pausing the Game
One of the most essential parts of any game is the ability to pause it. Our pause system will involve two mechanics :
- Stopping the game ’ s action
- Displaying a pause menu
In this section, we ’ ll work on the first one – stopping the game ’ south bodily process. This just involves deactivating objects so that they stop running their events, and late reactivating them so the game resumes. All of this will happen with the weigh of the “Escape” cardinal .
Let ’ s first create a new variable for pause :
- Go to obj_manager and open the Create event .
- This object can be found under “Objects” – > “Game”.
- here, create a variable called pause and set its value to false .
We ’ ll immediately tell the object to pause the game when Escape is pressed, by doing the follow :
- Go to obj_manager and click on “Add Event”.
Go under “Key
Pressed”, then “Others” and blue-ribbon “Escape” — this event will run when the Escape winder is hit.
- here, add a condition to check if pause is equal to false, meaning that the game is not presently paused.
- In that sheath, manipulation “Function Call” to run the
instance_deactivate_all affair, which merely deactivates all instances.
- This affair takes one argument that tells whether the current example should stay active or not. In this context the “ current exemplify ” is the director as that ’ randomness where the event is.
- We want the director to stay active so that it can resume the crippled when it needs to, so we ’ ll set the argument to true ( meaning it should keep the stream example active voice ).
- then change the pause variable to true .
The event above will pause the bet on, but we besides need actions to resume it. Let ’ s do the take after in the lapp Step event :
- Add the “Else” military action below the “If Variable” condition. Since that condition runs when the plot is not paused, the “Else” action will run when the game is paused.
- Attach a “Function Call” natural process to the “Else”
carry through and use it to run the instance_activate_all function.
- This function takes no arguments, and just reactivates all instances, efficaciously resuming the game.
- After that, change the pause variable spinal column to false .
You can now run the game, urge Escape and you will see all instances disappear. At that target they ’ ve wholly stopped running their events and are basically “ paused ”. You can then press Escape again to return them back to the claim state they were in when the game was paused .
sol that handles the actual hesitate, immediately let ’ s work on displaying a decent pause menu !
Pause Menu Screen
Let ’ s nowadays create a pause menu screen which will consist of a setting trope and two buttons : Resume and Menu .
Creating the Buttons
We have a rear object called obj_button_parent that already has all button behavior program. We just have to create objects that are children of that parent, and we ’ ll have fully functional, customs buttons in no time !
Let ’ s do the following to create a Resume button :
- In the “Objects” group, select the “Menu” group and create a new object called obj_resume_button.
- Assign the spr_button fairy to this, which can be found in the “Menu” group under “Sprites”.
- Open its Parent menu and set its rear to obj_button_parent.
- You will now see all of the parent ’ s events in this object .
Let ‘s change the text shown on the button, which is set up in the Create event as a variable .
- Find the “Create” event for this object, right-click on it and select “Inherit Event”.
- This event will automatically get a “Call Parent Event” action, which simply runs the parent object’s version of the event.
- This way, both the parent’s and the child’s versions of the event are called.
- Add an “Assign Variable” action and use it to set the value of the text variable, which stores the text string that is displayed on the button.
- Set its value to “Resume” (with quotes, as this is a string).
We ‘ll nowadays plan this release to resume the bet on when the player clicks on it .
- To program this clitoris ’ south behavior, we need to add to the “Left Released” event, which runs when the sneak has been lifted off the button.
- right click on the “Left Released” consequence and inherit it.
This will allow us to add actions to this event, and will besides run all existing actions in the parent ’ s event because of the “Call Parent Event” military action that was mechanically added.
- Add the “Assign Variable” action here and set the obj_manager ’ s pause variable to false.
- then add the “Function Call” carry through and call instance_activate_all to resume the game .
The “ menu ” clitoris will take the exploiter back to the main menu. Creating this button will be similar to creating the resume button :
- Create an object called obj_menu_button and assign the spr_button fairy to it. Make it a child of obj_button_parent.
- Inherit its “ Create” event and change its text variable to “Menu” ( or some early text that you ‘d like for this button ! )
Let ‘s course of study its behavior now :
- Inherit the “Left Released” event.
- In the event, add the “Go To Room” military action, which is used to change the room.
- Set the “Room” choice to rm_menu so the exploiter is taken back to the menu room .
- This is how simpleton it is to change rooms !
Making the Pause Sequence
The buttons for our hesitate menu are quick, so we ’ ll now design the menu interface in a sequence .
For an introduction to Sequences, add the enemy defeat animation to your game .
Let ’ s do the follow :
- In the Asset Browser, select the “Sequences” group and create a new Sequence asset. name this seq_pause_menu.
- In the Toolbox, open the Canvas Frame Settings and change the settings to the postdate :
- The Width and Height are set to 1280 and 720 as that ’ s the settlement of our game.
The Origin X and Origin Y are set to negative values that are half that resolution, so that the origin is placed in the top-left corner of the Sequence ( by default the origin is in the center ).
- At the circus tent of the Dope Sheet, on the very correctly, you will see a plain that stores the total length of the Sequence ( in frames ) ; by default it may be set to 60.
variety this to 1 alternatively as this will be a electrostatic, non-animated Sequence.
This finishes up our Sequence set-up, and we can nowadays start adding tracks to it to build our pause menu interface !
Adding a Background Image
We ’ ll add a background image to this Sequence, which will serve as the background for the pause menu. We ‘ll use the like image that is used in the main menu !
Let ’ s do the follow :
- In the Asset Browser, clear “Sprites”, then “Menu” and find the spr_menu_background fairy.
- Drag this fairy into the Track Panel or Canvas of the Sequence.
- It ‘s better to drag it immediately into the Track Panel as it will mechanically be placed at the correct stead, filling the Sequence wholly :
- It ‘s better to drag it immediately into the Track Panel as it will mechanically be placed at the correct stead, filling the Sequence wholly :
Placing the Buttons
We ’ ll now place our newly created Resume and Menu buttons in this sequence :
- First of all, make sure your playhead is on the first frame on the Dope Sheet, otherwise, by default, the buttons will only be visible on the selected frame ( if you placed it at another frame by error, you can simply move the asset key spinal column to the foremost frame ).
- In the Asset Browser, open the “Objects” group and then go into “Menu”.
- Find the obj_resume_button object ( the one we precisely created ) and drag it into the Canvas. You can move it about and place it wherever you like !
- The release looks empty right now since its actions are not being executed, but once you ‘re in-game, you will see the “Resume” text on it !
- Do the like for obj_menu_button : drag it into the Canvas and place it wherever you like .
Our pause menu is now fix, and we alone have to display it in the game !
New Asset Layer
We want the pause menu to appear above everything in the game, so we ’ ll create a new layer for it and display it there. Let ’ s do the follow :
- Open the rm_level_1 board.
- In the Layers panel, click on the release shown below to create an “Asset Layer” — this type of layer is used to display sprites and Sequences.
- name this layer “ GUI ” ( without quotes ) and place it at the top of the Layers list.
- nowadays repeat the same for rm_level_2 as it besides needs to have this layer for the hesitate menu to work .
Showing the Pause Menu
We ’ ll now show the pause menu Sequence when the Escape key is pressed. For that we ’ ll first base need to get the X and Y position of the camera, and then display the pause menu at the camera’s
position so the actor can see it .
We ‘ll need to use the television camera ‘s position to create the Sequence because Sequences are drawn inside the room, and not on the screen door directly .
Let ‘s do the follow :
- Go to obj_manager ( inside “Objects” – > “Game” ) and open its “Key Press – Escape”
- We ’ ll add new actions to the beginning “If Variable” circumstance, which checks if pause is false.
- Attach a “Function Call” action to run the camera_get_view_x
function. This gets the X position of the television camera.
- The argument will be view_camera, which points the presently active television camera in the room .
- Store the consequence in a impermanent variable called camera_x .
- Attach another “Function Call” action to run the camera_get_view_y function, which gets the Y status of the camera .
- The argument will be view_camera.
- Store the result in a irregular variable called camera_y .
- then add the “Create Sequence” action to create the seq_pause_menu sequence on the newly-created “GUI” level ( enter it with quotes ).
- We ’ ll create this sequence at the camera’s X and Y position, and store the ID of the Sequence in a variable called pause_seq ( not irregular ) .
Use the pursuit settings for your actions :
This will immediately show our hesitate menu Sequence when we press Escape !
Closing the Pause Menu
We now need to close this menu when the game is resumed. In the same event ( “Key Press – Escape” ), we ’ ll do the keep up :
- Add a “Destroy Sequence” military action and impound it to the “Else” action. This will run when the game is resumed.
- Use this action to destroy the pause_seq Sequence ( which is the variable storing the Sequence case we created ) .
This will nowadays close the pause menu when the plot is resumed, however there is one more put where the plot can be unpaused : the Resume
button. Let ’ s make it destroy the Sequence excessively :
- Go to obj_resume_button and open the Left Released event.
- Add the “Destroy Sequence” action here besides, and use it to destroy the hesitate menu Sequence.
- The pause menu variable will have to be retrieved from the coach aim, as that ’ s where it ’ randomness created ; so you will need to write obj_manager.pause_seq .
You can now run the game, crush Escape and see your pause menu ! Pressing Escape or clicking the Resume button in the menu should take you back into the game .
Animating the Menu
Since we ’ ve created our pause menu in a sequence, you can leverage this by animating your background and buttons !
here ’ s how you can do it :
- First of wholly, you will need to change the distance of the Sequence, as it ’ randomness presently set to 1 frame. As an case, let ’ s set it to 30 frames.
- You will then need to extend your asset keys so they fit the wholly sequence :
- We ‘ll make the background slither in. To do that, use the “Record a new key” button to create two keyframes on the background path.
- On the first keyframe, move the background outside the sail. then play the animation and you will see the background chute in !
Note : This sub-section is optional, and shows you how the sliding movement can be made smoother using curves. If you are not interested, skip to the “Finishing the Animation” sub-section below.
You can make this motion smooth by using Animation Curves :
- Expand the spr_menu_background track and select the position track (since we’re only changing the position of the sprite):
- Switch to Curve Mode, which allows you to apply Animation Curves to the selected sub-track (in our case, “Position”). This button can be found above the Dope Sheet:
- Convert your track to a Curve. This means that the selected sub-track (“Position”) will now use an Animation Curve instead of keyframes.
- Finally, open the Curve Library menu and change the curve from “Linear” to “Smooth”. Notice how the shape changes to an actual curve:
- This will result in movement that looks and feels much smoother, as can be seen in the next section below.
Finishing the Animation
future, do the lapp for your buttons : animate them with a slither movement and optionally, apply an Animation Curve. You will have now a pause menu with a dainty sliding animation !
This will make your bet on look much more polish, however do take care to make this vivification quick since you don ’ t want to keep players waiting !
Make certain that your sequence is not marked as loop : near the play controls, the iteration button should be unselected as shown below :
Let ’ s now move on to the last share of this tutorial, where we ’ ll create a help pop-up !
We ’ ll add a new assistant pop-up book in the main menu that displays the controls of our game. This is an essential separate of any game and will be made using Sequences besides !
Creating the Objects
Let ’ s create an object that will serve as our avail windowpane :
- In the “Menu” group under “Objects”, create an object called obj_help_window.
- Assign the spr_help_window fairy to it.
We besides need an object for the conclude button on this window, so lease ’ s add that excessively :
- Create an object called obj_help_close and assign the spr_help_close fairy to it.
- Make this object a child of obj_button_parent, as this is besides a button. We ’ ll use it to merely close the help oneself window.
- Inherit its “Create” event and set its text variable to an empty string (“”) as we don’t want any text to appear on this button.
Let ’ s blueprint the actual pop-up book now !
Designing the Pop-Up
We ’ ll create a new sequence and set up our avail window inside it. here ’ randomness how we ’ ll do it :
- Create a newfangled Sequence and name it seq_help_window.
- Open the Canvas settings from the Toolbox and use the surveil values ( they ’ re the same values we used for the pause menu ) :
We ‘ll now place a slightly guileless, bootleg background across the Sequence poll to create contrast for the help oneself pop-up book :
- In the Asset Browser, under “Sprites” – > “Menu”, you will find a fairy called spr_black_background .
- position it in the sequence and make it cover the whole sail – indeed this acts as our background.
- Stretch the track’s asset key so it lasts throughout the whole Sequence.
You ’ ll notice that this fairy is slightly guileless, to allow the independent menu to be visible behind the pop-up book. You can make it even more crystalline by adding the “Colour Multiply” parameter to the path and lowering its alpha !
Placing the Help Window
Let ’ s place the actual aid window now :
- First of all, make indisputable that your playhead is on the first gear frame .
- In the Asset Browser, find the obj_help_window aim and place it in the center of the Sequence Canvas.
- space the obj_help_close object into the Sequence, near the top-right corner of the help window .
- Make certain to stretch the asset key for both these tracks so they last throughout the whole sequence .
Our avail window is now complete, indeed let ’ s nowadays create a raw release to open this pop-up book !
We ’ ll create a new button which will be give in the main menu and will open the help pop-up book Sequence. here ’ s how we ’ ll do it :
- In “Objects” – > “Menu”, create a new object called obj_help_button.
- Assign the spr_button fairy to it.
- Make this aim a child of obj_button_parent, as we do with all button objects.
- Inherit its “Create” event and set its text variable to “Help”.
Let ‘s program its behavior nowadays :
- Right-click on the “Left Released” event and choose “Inherit Event” to inherit it.
- Add the “Create Sequence” action to create the seq_help_window Sequence. Create it on the “GUI” layer, which we ’ ll create later in the menu room.
- Set the “Target” for the Sequence to global.help_popup so it stores the Sequence ID in a global variable. We ’ ll late use it to destroy the Sequence.
- What is a Global Variable? It ‘s a variable that any instance can access, as opposed to a regular example variable which can alone be accessed in the case that created it. That ‘s why it ‘s called a “ global ” variable star — because it ‘s available globally in the game.
- Add the “Jump to Point” action and apply it to obj_button_parent. We ’ ll use this to move all buttons down by 1000 pixels so they disappear, as they should not be functional while the pop-up book is active.
Use the follow settings for your actions :
now go into the rm_menu room and add a “GUI” Asset Layer at the top :
Placing the New Button
Let ‘s place the newly Help push button in the main menu :
- Under “Sequences”, find seq_menu and open it. This contains the main menu animation and buttons.
- Place the Help button (obj_help_button) in the middle of the two existing buttons — you may need to move your playhead so you can see the buttons.
- Stretch its asset key so it lasts till the end of the Sequence.
- Look at the existing buttons and how they’re animated: each of them has two keyframes; let’s called them Keyframe A and Keyframe B:
- Keyframe A has the button at 50% scale on both axes. This is where their asset keys begin.
- Keyframe B has the button at 100% scale. This is where it stops animating.
- Use this same keyframe set-up to animate your newly-placed Help button, so it animates along with the other buttons.
- Of course, this is only optional and not a requirement!
All of this should nowadays enable us to open the help window, however we besides need a way to close it .
Closing the Pop-Up
The close push button ( obj_help_close ) should be able to close the pop-up book and move the menu buttons back to their original positions. Let ’ s do the follow :
- Open the obj_help_close object and inherit its “Left
- here, add the “Destroy Sequence” military action and use it to destroy the Sequence stored in the global.help_popup varying.
- The ball-shaped varying is now coming in handy, as we created it in a unlike object ( obj_help_button ) but are nowadays using it in obj_help_close !
- then add the “Jump to Point” carry through and apply it to obj_button_parent.
- Use this to move the buttons a 1000 pixels up, so they ‘re back in their original positions ( as we moved them a 1000 pixels down to make them disappear ) .
Use the following settings for these actions :
You can now run the game, open the aid window and close it ; you will besides notice that the independent menu buttons disappear while the aid pop-up book is open, so the player wo n’t unintentionally click on them !
You will see that the window is still blank, so we ’ ll now display the controls inside it !
We ’ ll draw our controls as text, so we need to create a limited baptismal font beginning to make our text look fancy :
- In the Asset Browser, select the “ Fonts ” group, go to the Create Asset menu and create a Font asset.
- diagnose this fnt_controls as this will be used to display our controls.
- The baptismal font will open in a Font Editor window in the Workspace. here you can select a baptismal font from the ones installed on your system, change its size and format .
here are the settings we ’ re going with for our baptismal font :
You can download more fonts at 1001fonts.com. Make certain to check the license of any font you download if you plan to release your game !
We ’ ll first set up a “string” variable that will store our controls text. A string varying is plainly a kind of varying that stores text rather of numbers .
To create a drawstring variable, you can merely make a fresh variable star and assign some text value to it. That text value has to be inside double quotes, as shown in the first base example below :
Since the second carry through doesn ’ metric ton have quotes around the text, it ’ sulfur actually good looking for a variable called “ Gurpreet ”, which is not what we want !
Let ’ s now set up our controls text by doing the take after :
- open obj_help_window and add the “ Create” consequence.
- Add an “Assign Variable” action and create a variable called controls.
- Apply the “CONTROLS\n” text to it. This is a regular string that says “CONTROLS”, and the “\n” part merely inserts a channel open frame into the string ( which is like pressing Enter
on your keyboard ! ).
- Add another “Assign Variable” action and assign a string to the controls variable, but this time, enable the “Relative” option. This will add that string to the textbook that already exists in that variable, basically joining them together .
Using this technique, we can keep adding controls to the variable star by adding strings to it :
You will notice that each modern string has “\n” in front man of it. This is simply adding a line break in the begin of each string, so that all the controls don ’ t appear in fair one line. besides make surely that all actions except the beginning one have “Relative” checked !
Drawing the Controls
Let ’ s now draw this text string by doing the comply :
- Add the “Draw” event to the obj_help_window object.
- Add “Draw Self” to make sure the exemplify itself is drawn.
- Add “Set Font” to change the font to the newly created fnt_controls baptismal font, and “Set Text Alignment” to change the text alignment to Center and Middle.
- Add “Set Draw Colour” to change the draw coloring material to black so the text is easier to read on the whiten avail window.
- Add “Draw Value” and draw the controls variable as the “Value”. The “Caption” airfield should be empty.
- Draw it at the relative military position of the example .
- finally, reset the draw color to whiten and the text alignment to Left & Top — these are their nonpayment values .
The origin of the spr_help_window sprite
is set to middle-centre, which is where we’re drawing the controls.
We’ve changed the text alignment to make sure it appears with the
correct alignment, however if your sprite’s origin is set to
top-left, you will not get the correct results.
Run the game now, snap on the Help push button and you will see the controls !
now you can animate this help window just like we animated the pause menu. good topographic point keyframes for vivification and optionally apply Animation Curves to make it smoother ! You can besides add more controls ( like “ E ” for interacting ) :
We have completed Hero ‘s trail ! You are nowadays conversant with how GML works and how GameMaker can be used for fast game growth. You are nowadays fix to create your own game from scratch ! Read or watch the Fire Jump series and create your own infinite scroller using GML Visual .