Check out my Patreon! www.patreon.com/peytonburnham Go there if you want to help me out a little more so I can make more videos like this (full turn-based RPGs, platformers, zelda-likes, beat 'em ups, etc)! There's a bunch of cool perks like getting videos before CZcams does, voting on future series, and getting the project files and assets from future videos! Thanks!
one of the things I love about your videos is that the comments garner such a wide range of experience from folks, every comment I see is either thanking you for the tutorials, talking about the things they made from the tutorials, or someone asking for help with something that wasn't exactly made apparent in the video and getting helpful replies from multiple people. I love it here :)
Timestamps for reference: 3:50 Declaration of variables in obj_side_menu 4:23 Array of options 5:21 Draw the menu 7:20 Brief demo 7:40 Draw the options, set up font (skip to10:07 if I already have a font) 9:27 Clean up event: font_delete the custom font. 10:07 Draw font 11:00 Use of for loop: draw the options if i < length of the option array 11:46 Add padding to the text 12:33 op_space * i will ensure that the options are not drawn on top of each other, they are drawn like a normal menu 13:04 Demo 13:20 pos variable in Create event - we're gonna start being able to select the options 14:25 up and down key 14:42 We want to prevent the pos from going above 2 or below 0. 15:44 Changing text colour to show which one selected 16:25 if pos == i, _c = c_yellow 17:12 Step event: add a switch statement (for the purpose of entering the option) 19:31 Demo 19:45 Submenu making 20:01 Make the option array 2-dimensional, add a variable menu_level (note to self: I could use regions as a way to open and close to see what are the options under the, say, settings menu. Here, he does it by separating the menus.) 21:09 Create event: set op_length to 0, since we will set the option lengths dynamically in the step event. 22:04 Change that bit of code to draw from a 2d array instead of the previous 1d array (option[menu_level, i]) 22:20 Changing up the organisation of the switch statement, and there will be another switch which checks for menu_level. 24:20 Set menu_level back to 0 if pressing back in settings menu, and set menu_level to 1 if pressing settings menu 25:00 Fixing the bug (the for loop) [Done by setting a local var _sml, whereby, in the switch statement of the menu_level, if it does not equal to menu_level, then set the pos = 0. This is to prevent the unexpected bug of the for loop looking for an option 3 in the main menu when there isn't one.] 26:45 Demo 27:24 Dynamically get width and height of menu 27:59 An important note related to string_height 29:34 The local variable _new_w: setting new menu width based on which option the longest 30:31 Centralise the menu
to play a sound when you change the menu lines create a line called last_selected = 0; in create event and go to step event now in step event, put this code there if (pos != last_selected) audio_play_sound(YOUR SOUND NAME, 1, false); last_selected = pos; thats all
I appreciate your help man, I'm pretty new so I can't figure out how to make small things like this, but this definitely helps But what about a playing a sound when you press "accept"? How would you do that?
@@skymed3095 you can do something like if keyboard_check_pressed(vk_enter) && !audio_is_playing(ACCEPTSOUND) { audio_play_sound(ACCEPTSOUND, 1, false) } This i think, i hope it works good luck
Oh wow you explained everything so easily and clearly that even as a non dev like me can understand. I'm trying to understand this cause I plan to give my sister a gift for her bday next year using your dialogue tutorial. I made her a simple platformer this year following random tutorials here on youtube and she absolutely loved it. So I'll try my hand at something more ambitious next year. Thanks a lot for these! I really appreciate it.
if you want to use the WASD keys for the menu, put an OR state in the middle for example: up_key = keyboard_check_pressed(vk_up) || keyboard_check_pressed(ord("W"));
It might be good to know that you can also literally type "or" (no quotes btw) and it would do the same thing. But it's better (imo) to get used to typing these | | :)
Anyone having pixel issue with their 9 slice by the end- I recommend putting the code for centering the x and y in a " x = round( [code] ) " to round it. That solved the issue for me.
Around 27:57 If you're using a Font that isn't set as by sprite. You could use the below code, with "fnt_menu..." being the custom font. Take this with a grain of salt, it worked for me, but I do not know much about coding. height = op_border * 2 + font_get_size(fnt_menu_dungeonfont) + (op_length - 1) * op_space;
@@myers4924 I know this was a month ago but i need an answer desperately, how do you add a normal font into it without it being a sprite font???? i need to know! thank you :)
If anyone else is trying to use this on a 1920 x 1080 room, the easiest thing to do is to scale his values by 10. For example, where he put "width = 64" in the create page, I put "width = 640". Change this, the height (860), op_border(80), op_space(160) and also the last number of obj_settings --> Create --> line "global.font_main"... from 1 to 5. Then the rest of the math will all make sense. I also changed my font sprite to 70x90 and my textbox sprite to 200x200. Double check all these listed values for a 1920x1080 room and it will all work as demonstrated in the video!
i’ve bingewatched all your programming videos and made something… this guide is sooo coool! man i never thought it could be so interesting!!! pleeasaeee continue these tutorials it’s super cool!!!! also im quite surprised that your channel is so small so keep it up !!!!!!
Quick tip: Way to go through menu options without branches: just after `pos += down_key - up_key;` you can add `pos = (pos + op_length) % op_length;` instead of "if" statements
I started using GameMaker recently. These tutorials really helped me understand how GameMaker works. Although, i used GameMaker Visual to code, i was able to make sure I was matching the code by useing the Live Preview function, which shows your code if typed out, but doesnt permanently convert it. Thanks for this 😊
I had to subscribe man seriously you’re a big help c: will you be covering an rpg battle system as well? I’ve been trying to figure out how to do an earthbound type of battle perspective, like how it’s first person but I dunno how to approach it..
Thank you! And I'm not sure yet what types of gameplay-oriented systems I'll be covering. As far as turn-based combat goes, an Earthbound style system would be one of the easier ones to cover but they're still pretty involved! But never say never, I suppose!
Thank you so much for posting this, can't wait for the textboxes, small nitpick though, could you zoom in on your code, sometimes I can't read it but other than that great job
This video's quite good, but I do wanna add something for anyone passing through. in 15:08, you dont really need to use 2 if statements, you can simplify it down to: pos = (pos + op_length) % op_length; or... pos = (pos + op_length) mod op_length; Basically, we do a modulo on where we're selected with op_length. Hope this helps!
That was an awesome video! I loved the tempo\speed of the video too. My UI always gets messy when I add sub menus and features. I like what you did as its quick/simple and dynamic. I dont know if it matters much, but I am not sure about having for loops in the draw event. Can be a cpu/gpu killer if your not careful. Lately I like to use a menu_controller object which keeps track of what menu your at and what buttons to show. Then I have button objects that can change as needed in size, text or image. Also more advanced animations and such using delays or loading. They are easy to control too as each menu button is an object and all that entails. It can help when mixing input from mouse, keyboard or joystick as I like to have all of them available. But anyways, I really liked this video and your code is pretty awesome!
Great video it helped me a lot to construct some cool menus in my projects. However I found a small problem, if your submenu has less options than your initial menu level you get an Index error. Example: options[0, 0] = "New Game"; options[0, 1] = "Load Game"; options[0, 2] = "Settings"; options[0, 3] = "Exit Game"; options[2, 0] = "Sound"; options[2, 1] = "Back"; If you choose Settings you will trigger an index error because pos will be 2 but pos in options[2] takes values 0 and 1, even if you change the pos and menu_level in the Step Event inside the switch statement. One way to solve this (bad) is to add an alarm trigger that deactivates the Draw Event for miliseconds OR in my case, I just made a 1d array of menus and I spawn additional objects for each submenus. Again, I'm just mentioning this for educational purposes. This example of menu system you propose is solid and follows good practices. Great job and good luck on your works!
I had the same issue, your comment helped me a lot, but, I found a super super simple way to fix it. instead of just putting //Settings case 3: menuLevel = 1; break; instead, change the op_Length before changing menu level, like this. case 3: opLength = array_length(option[1]); menuLevel = 1; break;
your tutorial , are insane, im not even an english speaker, and i have a lot of diffuculty while listening video in english, but not on your video, you are talking clearly, we hear every word you spell, thanks for these tutorial.
Amazing Tutorial - I actually supported your Kickstarter and somehow never realized you did tutorials like this. Keep up the incredible work on your tutorials, this was very clear and helpful to expand upon.
Holy crap man. Excited for Starcross to come out, it looks like an absolute blast. Thank you for doing these tutorials for us in the meantime. You've earned a loyal fan.
i know its been quite a while but i really got into gamemaker thanks to you, and i am finally able to make my own games instead of just modding thank you, you just got my sub =]
If you're building this menu into the RPG game from the previous tutorials, and if you want to access the menu from your game, I added this to the beginning of the step event for the player object (obj_player): if (keyboard_check_pressed(vk_escape)) { room_goto(rm_title_screen); instance_deactivate_object(obj_player); } It makes it so that pressing the escape key (vk_escape) loads the menu (rm_title_screen). It also deactivates the player so they don't show up on top of the menu.
Great tutorial! I suggest putting this video in a playlist, because i couldn't find it while going through your playlists. After the RPG basics tutorial series i wanted to watch more tutorials, so clicked on the first dialogue tutorial video because it was in a playlist, and only at the beginning of that video i realized there was a previous video (this one) i had missed, and only because that video mentions it.
a lot of cutting, would be nice to be able to just see how you do things from scratch, adding in, importing, creating new folders and so on, other than that it's great. don't listen to those that complain about too much information, there is no such thing, but there is a setting on youtube to speed up a video in case people are in a hurry 😜
Thank you!! This is the best menu tutorial that I've found online, and helped me develop my menu system. I'm just getting into GameMaker2 so this tutorial was very helpful for me. Infinitely grateful!
Hey Peyton this series is helping me develop my own game right now, and I'm very happy that this series exist but I need help with a problem with the menu. My menu select is very fast, if i press up or down i just freaks out and lands on a random option. Nevermind, I got it lmao!
Thank you very much for your videos, Peyton - I just recently got started with GameMaker Studio 2 and your videos have been entertaining, educational and extremely helpful!
i fixed the switching menu bit by accident and when the fixing for loop bit played i realized i hadnt fixed anything lol it was torture to get back to the error bit BUT THIS TUTORIAL IS TOOO GOATED
Thanks man, this video really helped, though. I do a have a question, Can you make a part 2 where it covers actually setting up stuff like the volume, reso. etc?
i got a problem. The game is running perfectly, i did everything you said, but when the menu opens, the Menu background sprite isn't there anymore. There's just the big black void behind the text and it looks to me like it's not well-centered like it's supposed to. Can you and the others help me, please? UPDATE: I found where the problem is coming from. It's the part where you have to position the menu. This part, to be more precise: width = _new_w + op_border*2; height = op_border*2 = string_height(option[0, 0]) + (op_length-1)*op_space; I deleted it and the background menu sprite reappeared, but it looks ugly and it doesn't fit the options nicely. Any ideas on how i can fix it?
Great video, thank you so much, this was just the right thing to get me to finally program some menu systems for my games! I will definitly check you dialogue system too, looking forward to that!
If your menu disappears when you add Center Menu code, try dividing it by different values. I had divide my x by 9 and y by 7 to center it. instead of the /2
if keyboard_check(shift_key) { move_spd = 2; } if keyboard_check_released(shift_key) { move_spd = 1; } the values of the move speed can be whatever fits your game
Great tutorial. Just watched it and gotta have a go on my own now. I also looked up your game. It sounds interesting and I'll have a eye on it. Especially since you also go for a Switch version :) I'll need your other tutorials too, so, keep going. It'll help to get to know your game to a bigger public.
I love your tutorial series so much. In my opinion, the most helpful one's out there. I really take my time watching them quite thoroughly (I'm a very beginner and need the time to understand it all). I have one open question, maybe someone who reads this find the time to explain it to me. So we define the position variable in the create-event. (pos = 0). Then, in the step event, we define the current position depending on which buttons we press, and highlight the selected string. My question is: how does GM know from the start, that the pos we defined overlaps with the same position as the first string in our array ? (In this example: "Start Game"). I'm pretty sure I'm overthinking it. But I really want to understand how it works, so I'd be super thankful for any help I'd get here!
I don't speak your language, but if I understood correctly from the translator what your question is, then the gmc initializes what is in create first, and then step, so when it comes to step, the gmc checks pos with option
in the option, the zero cell is equal to "start game" and since the position is 0, then the zero cell will be output, and the zero cell is the start game)
I love this menu system. For some reason though on my thinner letters like l and i, it leaves a huge space that shouldn’t be there while all the other letters are correctly spaced
I'm new to coding, I have zero knowledge of it and even tho your videos are basic, I'm still worried if I can understand all of this. Like what's the logic behind those codes? Do I need to understand it first or I just need to follow the tutorial and other tutorials and wait for the day I eventually get it?
If you haven’t watched my “How to make an RPG” series, watch that first, it goes by everything very slowly and i explain how everything works! It’s a bit simpler than this video. At first you’re going to be learning a lot at once so it might feel like you don’t understand, but thats how learning ANY new thing works! Keep following beginner tutorials, pay attention to them very closely, and REWATCH many of them after you’ve finished them. That will help a lot. Soon lots of this stuff will just stick with you and you’ll find your footing! Just keep going!
In the draw event, you'd do something like: draw_sprite(spr_triangle, 0, x, y+op_border+(op_space*pos)) may need to offset the values depending on your sprite, but this should work
HELP, when I try to start the game, it says that, the code "draw_text( x+op_border, y+op_border + op_space*i, opción[i]) it's not set before reading it, can someone tell me how ti fix it ????? 😭😭😭
my code isn't perfect but I have something like this working well enough in my game describing what you're asking. For set up I have 2 instances layers for my game, one with all of the main elements and visuals like the player, obstacles, interactables, etc and one just for holding meta objects. In the step event of an overall controller object, I set up a if key pressed input that would be pausing the game, and use this line that toggles the state of being paused and not: global.gamePause = -global.gamePause + 1; then I have an if then statement that says if the game is paused, everything on the main game layer's image speed will be 0 to stop all animations with the instance of the menu being created on a separate layer above (additionally in the player's code if the game is paused, all movement code is stopped). else, the image speed of the main game layer is set back to it's original and the menu instance is destroyed. There may be a better way to do this or explain this but it's the best I have for now!
I can press spacebar on 'settings' and have it take me to the next menu but when I click "Back" it does not go back to the pause menu. Instead, it takes me into my game as if I had pressed "Start Game." Has anyone else had this issue, or could possibly guess as to why this might be happening? Edit: Never mind. I figured it out. I had typed accept_key = keyboard_check(vk_space) instead of accept_key = keyboard_check_pressed(vk_space). So, 'Back' was actually bringing me back to the pause menu, but because the spacebar was still pressed, it would select "Start Game" immediately then I would find myself in my game without ever seeing the pause menu.
Glad you figured it out on your own! It's great to start building that skill of being able to identify little problems like that and knowing what was actually happening! Great work!
I don't know why but I can't for the life of me get the camera centering to work, I've got the x = camera_get_view_x(view_camera[0]) + camera_get_view_width(view_camera[0])/2 - width/2; y = camera_get_view_y(view_camera[0]) + camera_get_view_height(view_camera[0])/2 - height/2; but for whatever reason it disappears whenever I use this code.
I had this issue and it ended up being me forgetting to configure my viewport lol Make sure U enabled viewport, make viewport 0 visible, configure your camera properties height and width and viewport properties width and height to whatever your games properties are and have the camera follow the obj_tile_menu (or whatever you chose to call your menu object) and it should show up when you run the game 👍
Great video! But I still have a few questions. How would I go about making 2 more submenus? I tried just essentially following all the steps again creating 2 more cases. But my new submenues only have 2 cases in them each. But for some reasong when I try to open them it gives me an error. Saying there was something wrong on my Draw event 12, this one, draw_text_color(x+op_border, y+op_border + op_space*i, option[menu_level, i], _c, _c, _c, _c, 1);
You need to update your op_length variable when switching to a smaller menu(in your example a menu with 2 cases), let's say that the main menu has three cases, when you switch into your smaller submenu without updating op_length, gamemaker remembers that op_length is three so when it's trying to draw the submenu it returns an error because there is no 3rd case. Here's my code in the step event in case you don't understand: //Check for accept input if acceptK { //Switch pos switch menuLevel { //Main menu case 0: switch pos { case 0: room_goto_next(); break; case 1: menuLevel = 1; break; case 2: menuLevel = 2; opLen = menuLevel; break; //Updating opLen to current menu level case 3: game_end(); break; } break; //Options menu case 1: switch pos { case 0: break; case 1: break; case 2: break; case 3: menuLevel = 0; break; } break; //About menu case 2: switch pos { case 0: break; case 1: menuLevel = 0; break; } break; } } Sorry for late response and I hope this helps :)
Damn. Thanks for Tutorial. Your demo is windows only sadly which I only have m1 Mac which does not allow for bootcamp :( Congrats though on the kickstarter for 15K.
I'm running into a few problems while doing it. First of all, the object I put in the room is very small when I run it. What should I do? and finally, can we get the font ready instead of creating it ourselves?
1. just put object in the room, dont stretch It :) 2. create font(right click on workspace>assets>create font), name it font_main(or whatever you want), then in obj_settings create event instead of tutorial code put these code: global.font_main = font_main;
@@Wakakakakaku how would i type this code for the clean up would it be it says idk what im doing wrong anytips? trying to delete non-existing font. at gml_Object_Obj_settings_CleanUp_0 (line 1) - font_delete(global.font_text);
why does my menu vanishes when i use that one last code (setting the center menu part)? I believe i did everything as the video shown //center menu x = camera_get_view_x(view_camera[0]) + camera_get_view_width(view_camera[0])/2 - width/2 y = camera_get_view_y(view_camera[0]) + camera_get_view_height(view_camera[0])/2 - height/2
i got this error ERROR in action number 1 of Create Event for object oSetting: global variable name 'font' index (100030) not set before reading it. at gml_Object_oSetting_Create_0 (line 1) - global.font.main = font_add_sprite(xxxfont, 32, true, 1) how do i fix it?
I keep entering a code error whenever I try to load up my game. The issue is with the 5th line of code in obj_settings and create. It keeps saying that font_main is not established and idk what to do :(
the background on my menu seemingly duplicated itself without its animation behind the first one (that has the animation) and the second one is wider than the first, anyone know how to fix this?
If you've been having trouble with deformed sprites like I have, here's a workaround. Simply change the Tile Mode of each part of the sprite's Nineslice to Repeat.
what if the next menu level has less options than the first menu level? I kinda merged your video and shaun spalding's, I have a little arrow to show what you're selecting as well as colour. But yeah I have that error. Here's my draw code, the error is "var txt = menu[menuLevel, i]" for (var i = 0; i < menuItems; i++) { var offset = 2; var txt = menu[menuLevel, i];
Quick question regarding the initial length and width values. In the beginning of the tutorial you set width and height values for the menu border and later on you made the menu border size dependent on the text and fonts. Would the initial length and width values still matter? Or could you just set them to 0 and let the step event change them dynamically according to what’s being displayed?
Hi There Peyton, followed your tutorial to the dot! The difficulty skyrockets in this one compared to your 6-part series. I love your tutorials so far! they are really helpful! I managed to make the menu work as intended but with a few problems: 1st of all I do not know how to adjust the height and width of the box and letters to make them appear a bit bigger compared to the screen and 2nd when I click on "back" on the settings menu the game crashes and it returns the following error: ############################################################################################ ERROR in action number 1 of Draw Event for object obj_title_menu: Variable Index [3] out of range [3] at gml_Object_obj_title_menu_Draw_0 (line 5) - var _op_w = string_width(option[menu_level, i]); ############################################################################################ gml_Object_obj_title_menu_Draw_0 (line 5) Thanks again in advance! Keep up the awesome work!!
I'm having this same issue with the menu options. The only way it works for me currently is if both menus have the same amount of choices. My best guess is because arrays now only come in 1D, no longer 2d, technically.
STEP EVENT //get inputs up_key = keyboard_check_pressed(vk_up); down_key = keyboard_check_pressed(vk_down); accept_key = keyboard_check_pressed(vk_enter); //store number of options in current menu; op_length = array_length(option[menu_level]); //move through the menu pos += down_key - up_key; if pos >= op_length {pos = 0}; if pos < 0 {pos = op_length-1}; //using the options if accept_key {
var _sml = menu_level;
switch(menu_level) {
//pause menu case 0: switch(pos) { //start game case 0: room_goto_next(); break;
//settings case 1: menu_level = 1 break;
//quit game case 2: game_end(); break; } break;
//settings case 1: switch(pos) { //window size case 0:
break; //brightness case 1:
break; //controls case 2:
break; //back case 3: menu_level = 0; break;
} break;
} //set position back if _sml != menu_level {pos = 0}; //correct option length op_length = array_length(option[menu_level]); }
I excuse in advance for bad English If your viewport has a number but the window resolution has an higher one (something like the viewport being 288x216 and the window being 864x648) and you're trying to make a pixel art game then you might have a problem, the pixels will have a bad scale due to the width being a odd number, to resolve that problem, add this line: if _new_w%2 == 1 {_new_w += 1}; It will check if it's an odd number, then add 1 to the variable to make it an even one
Is there any way to use the sprites that come in with GM2 rather than making your own? I really like the look of MS Gothic and I want to find a way to use that instead, but it's just a font. Not a sprite.
Thank you for the tutorial, it's really well made. I need help please; I've been trying to find a way to make a pause menu like in the beginning of the video with but it keeps telling me that op_length isn't set before being read. Here's my code : In the step even of the player object: pause_key = keyboard_check(vk_escape); if pause_key = 1 { instance_create_layer(0, 0, "Instances", obj_pause_menu); } I haven't made any code to remove the instance yet because I'm not able to create it in the first place. I'd really appreciate any help, thanks.
remove the "= 1" from the if statement. also when checking for things in if statements, you must use two equal signs. one equal sign means that you are setting the value of something, and two equal signs are how you check for the value of something inside a conditional (which is if statements, while statements, etc.). also the pause_key variable would be a boolean, which is true or false. checking if it's equal to one wont work because one is an integer, and pause_key is not an integer value. you would use if pause_key == true. however, that is unnecessary when checking if a boolean is true. hope this helps and was informative for you, id recommend watching some coding basics tutorials. learning things in once language can translate to all languages, even with syntax differences theres universal things that you need to know in coding
I’m not the video poster, but in the step event within the input checks, where there are two if loops under “//move through the menus”, you could put an audio play in each of those loops.
Check out my Patreon! www.patreon.com/peytonburnham
Go there if you want to help me out a little more so I can make more videos like this (full turn-based RPGs, platformers, zelda-likes, beat 'em ups, etc)!
There's a bunch of cool perks like getting videos before CZcams does, voting on future series, and getting the project files and assets from future videos! Thanks!
i have a question
can u explain how to make a sub menu if its option[0, 0]
thx
i cant seem to see the text in my menu
Is there a way to have this menu system work with a mouse-based input?
one of the things I love about your videos is that the comments garner such a wide range of experience from folks, every comment I see is either thanking you for the tutorials, talking about the things they made from the tutorials, or someone asking for help with something that wasn't exactly made apparent in the video and getting helpful replies from multiple people. I love it here :)
Timestamps for reference:
3:50 Declaration of variables in obj_side_menu
4:23 Array of options
5:21 Draw the menu
7:20 Brief demo
7:40 Draw the options, set up font (skip to10:07 if I already have a font)
9:27 Clean up event: font_delete the custom font.
10:07 Draw font
11:00 Use of for loop: draw the options if i < length of the option array
11:46 Add padding to the text
12:33 op_space * i will ensure that the options are not drawn on top of each other, they are drawn like a normal menu
13:04 Demo
13:20 pos variable in Create event - we're gonna start being able to select the options
14:25 up and down key
14:42 We want to prevent the pos from going above 2 or below 0.
15:44 Changing text colour to show which one selected
16:25 if pos == i, _c = c_yellow
17:12 Step event: add a switch statement (for the purpose of entering the option)
19:31 Demo
19:45 Submenu making
20:01 Make the option array 2-dimensional, add a variable menu_level (note to self: I could use regions as a way to open and close to see what are the options under the, say, settings menu. Here, he does it by separating the menus.)
21:09 Create event: set op_length to 0, since we will set the option lengths dynamically in the step event.
22:04 Change that bit of code to draw from a 2d array instead of the previous 1d array (option[menu_level, i])
22:20 Changing up the organisation of the switch statement, and there will be another switch which checks for menu_level.
24:20 Set menu_level back to 0 if pressing back in settings menu, and set menu_level to 1 if pressing settings menu
25:00 Fixing the bug (the for loop) [Done by setting a local var _sml, whereby, in the switch statement of the menu_level, if it does not equal to menu_level, then set the pos = 0. This is to prevent the unexpected bug of the for loop looking for an option 3 in the main menu when there isn't one.]
26:45 Demo
27:24 Dynamically get width and height of menu
27:59 An important note related to string_height
29:34 The local variable _new_w: setting new menu width based on which option the longest
30:31 Centralise the menu
to play a sound when you change the menu lines
create a line called
last_selected = 0; in create event and go to step event
now in step event, put this code there
if (pos != last_selected) audio_play_sound(YOUR SOUND NAME, 1, false);
last_selected = pos;
thats all
where to write the code?
@@toddqdev Read carefully!!
last_selected = 0 goes into CREATE EVENT
the second code
if (pos != last_selected) audio_play_sound(YOUR SOUND NAME, 1, false);
last_selected = pos; GOES INTO STEP EVENT
@@RandomGameBenchmark Alright sorry and thanks!
I appreciate your help man, I'm pretty new so I can't figure out how to make small things like this, but this definitely helps
But what about a playing a sound when you press "accept"? How would you do that?
@@skymed3095 you can do something like
if keyboard_check_pressed(vk_enter) && !audio_is_playing(ACCEPTSOUND)
{
audio_play_sound(ACCEPTSOUND, 1, false)
}
This i think, i hope it works good luck
This is one of the best tutorials I have seen, please continue this. Doing a great job.
Thank you so much!
@peytonburnham4316 how did you crate a folder
@@Axogamerloveryou click the plus button at the top of the asset menu and make a group :)
Oh wow you explained everything so easily and clearly that even as a non dev like me can understand. I'm trying to understand this cause I plan to give my sister a gift for her bday next year using your dialogue tutorial. I made her a simple platformer this year following random tutorials here on youtube and she absolutely loved it. So I'll try my hand at something more ambitious next year.
Thanks a lot for these! I really appreciate it.
How did it go? Did you manage to make something cool?
Coolest brother(?) ever
if you want to use the WASD keys for the menu, put an OR state in the middle for example:
up_key = keyboard_check_pressed(vk_up) || keyboard_check_pressed(ord("W"));
It might be good to know that you can also literally type "or" (no quotes btw) and it would do the same thing. But it's better (imo) to get used to typing these | | :)
Anyone having pixel issue with their 9 slice by the end- I recommend putting the code for centering the x and y in a " x = round( [code] ) " to round it. That solved the issue for me.
Legend.
this has been driving me crazy for the past hour, thank you
Having almost bit the edge of my desk in frustration at not getting a menu system working properly, I found this. Such a clear and easy tutorial.
Around 27:57 If you're using a Font that isn't set as by sprite. You could use the below code, with "fnt_menu..." being the custom font. Take this with a grain of salt, it worked for me, but I do not know much about coding.
height = op_border * 2 + font_get_size(fnt_menu_dungeonfont) + (op_length - 1) * op_space;
ffs tysm
fnt menu doesnt exist apparently??
@@ripihy fnt menu is part of the font name. My font was named "fnt_menu_dungeonfont", yours could be something else like "Comic_Sans"
@@myers4924 I know this was a month ago but i need an answer desperately, how do you add a normal font into it without it being a sprite font???? i need to know! thank you :)
tysm!
I honestly find these more straightforward and clear than the official gamemaker tutorials. Thanks!
If anyone else is trying to use this on a 1920 x 1080 room, the easiest thing to do is to scale his values by 10. For example, where he put "width = 64" in the create page, I put "width = 640". Change this, the height (860), op_border(80), op_space(160) and also the last number of obj_settings --> Create --> line "global.font_main"... from 1 to 5. Then the rest of the math will all make sense. I also changed my font sprite to 70x90 and my textbox sprite to 200x200. Double check all these listed values for a 1920x1080 room and it will all work as demonstrated in the video!
Thank you for your help!
@@JackHuntYou you’re welcome, it’s this god on the video that we really owe our thanks to xD
What about the center menu?
When I say this is an upgrade to my previous menu system it is NOT an understatement, thank you! Looking forward to checking out more of your stuff!
!understatement
i’ve bingewatched all your programming videos and made something… this guide is sooo coool! man i never thought it could be so interesting!!! pleeasaeee continue these tutorials it’s super cool!!!! also im quite surprised that your channel is so small so keep it up !!!!!!
well spoken perfectly paced informative tutorial
cyranek rpg confirmed?
Quick tip: Way to go through menu options without branches: just after `pos += down_key - up_key;` you can add `pos = (pos + op_length) % op_length;` instead of "if" statements
Nice tip! for some reason my code didn't work with the if statements, but with your code it did.
I started using GameMaker recently. These tutorials really helped me understand how GameMaker works. Although, i used GameMaker Visual to code, i was able to make sure I was matching the code by useing the Live Preview function, which shows your code if typed out, but doesnt permanently convert it. Thanks for this 😊
Gotta say very well explained for beginners such as myself.
That’s great to hear!
I had to subscribe man seriously you’re a big help c: will you be covering an rpg battle system as well? I’ve been trying to figure out how to do an earthbound type of battle perspective, like how it’s first person but I dunno how to approach it..
Thank you! And I'm not sure yet what types of gameplay-oriented systems I'll be covering. As far as turn-based combat goes, an Earthbound style system would be one of the easier ones to cover but they're still pretty involved! But never say never, I suppose!
Thank you so much for posting this, can't wait for the textboxes, small nitpick though, could you zoom in on your code, sometimes I can't read it but other than that great job
Oh great idea! I’ll see if I can increase the font size in gamemaker or something before i record the next video!
@@peytonburnham4316 how do I create a new folder
@@ok-mb1bn even if you do that, its still hard to read it
This video's quite good, but I do wanna add something for anyone passing through.
in 15:08, you dont really need to use 2 if statements, you can simplify it down to:
pos = (pos + op_length) % op_length;
or...
pos = (pos + op_length) mod op_length;
Basically, we do a modulo on where we're selected with op_length.
Hope this helps!
That was an awesome video! I loved the tempo\speed of the video too. My UI always gets messy when I add sub menus and features. I like what you did as its quick/simple and dynamic. I dont know if it matters much, but I am not sure about having for loops in the draw event. Can be a cpu/gpu killer if your not careful. Lately I like to use a menu_controller object which keeps track of what menu your at and what buttons to show. Then I have button objects that can change as needed in size, text or image. Also more advanced animations and such using delays or loading. They are easy to control too as each menu button is an object and all that entails. It can help when mixing input from mouse, keyboard or joystick as I like to have all of them available. But anyways, I really liked this video and your code is pretty awesome!
hey sir, i know its already been a year since you created this tutorial. I just wanted to say thankyou so much, I learn a lot from your videos.
Great video it helped me a lot to construct some cool menus in my projects. However I found a small problem, if your submenu has less options than your initial menu level you get an Index error.
Example:
options[0, 0] = "New Game";
options[0, 1] = "Load Game";
options[0, 2] = "Settings";
options[0, 3] = "Exit Game";
options[2, 0] = "Sound";
options[2, 1] = "Back";
If you choose Settings you will trigger an index error because pos will be 2 but pos in options[2] takes values 0 and 1, even if you change the pos and menu_level in the Step Event inside the switch statement.
One way to solve this (bad) is to add an alarm trigger that deactivates the Draw Event for miliseconds OR in my case, I just made a 1d array of menus and I spawn additional objects for each submenus. Again, I'm just mentioning this for educational purposes. This example of menu system you propose is solid and follows good practices. Great job and good luck on your works!
I had the same issue, your comment helped me a lot, but, I found a super super simple way to fix it.
instead of just putting
//Settings
case 3: menuLevel = 1; break;
instead, change the op_Length before changing menu level,
like this.
case 3: opLength = array_length(option[1]); menuLevel = 1; break;
just number in order from 0,1,2 and so on, of course there will be an error if you jump from 0 to 2
@@kingofspades9720omg thanks so much man, was having a headache with this error
@@botijooj Glad it could help!
your tutorial , are insane, im not even an english speaker, and i have a lot of diffuculty while listening video in english, but not on your video, you are talking clearly, we hear every word you spell, thanks for these tutorial.
Amazing Tutorial - I actually supported your Kickstarter and somehow never realized you did tutorials like this. Keep up the incredible work on your tutorials, this was very clear and helpful to expand upon.
Holy crap man. Excited for Starcross to come out, it looks like an absolute blast. Thank you for doing these tutorials for us in the meantime. You've earned a loyal fan.
i know its been quite a while but i really got into gamemaker thanks to you, and i am finally able to make my own games instead of just modding
thank you, you just got my sub =]
If you're building this menu into the RPG game from the previous tutorials, and if you want to access the menu from your game, I added this to the beginning of the step event for the player object (obj_player):
if (keyboard_check_pressed(vk_escape)) {
room_goto(rm_title_screen);
instance_deactivate_object(obj_player);
}
It makes it so that pressing the escape key (vk_escape) loads the menu (rm_title_screen). It also deactivates the player so they don't show up on top of the menu.
Great tutorial!
I suggest putting this video in a playlist, because i couldn't find it while going through your playlists.
After the RPG basics tutorial series i wanted to watch more tutorials, so clicked on the first dialogue tutorial video because it was in a playlist, and only at the beginning of that video i realized there was a previous video (this one) i had missed, and only because that video mentions it.
i can't believe you made that font!! it looks just like old rpgmaker games or ds rpgs...i wish i could download it
greatest people on earth
Bro i love you. thats so many videos of you that helped me. every time i find my answers with you
a lot of cutting, would be nice to be able to just see how you do things from scratch, adding in, importing, creating new folders and so on, other than that it's great.
don't listen to those that complain about too much information, there is no such thing, but there is a setting on youtube to speed up a video in case people are in a hurry 😜
I love this guy and his tutorials
Thank you!! This is the best menu tutorial that I've found online, and helped me develop my menu system. I'm just getting into GameMaker2 so this tutorial was very helpful for me. Infinitely grateful!
Hell yeah! Thanks for the stellar tutorial man, hope your game is a success it looks phenomenal!
You, sir, are the real MVP. This series has been a tremendous kick-start.
I would love to see this system used for a turn-based rpg combat system!!
Could you make a tutorial for how to make the buttons in the sub menu (Window size, Brightness, and Controls) actually work?
best tutorial i've done and i've been hopeless with everyone elses tutorials, thanks.
thank u so much for creating this kind of content. u're really helping me a lot :)
literally a life saver for this one WOOO i had been looking for something like this all WEEK THANK YOU
that last part when you were trying to say itchio was hilarious lmao
Hey Peyton this series is helping me develop my own game right now, and I'm very happy that this series exist but I need help with a problem with the menu. My menu select is very fast, if i press up or down i just freaks out and lands on a random option.
Nevermind, I got it lmao!
Wait how'd you fix that?
Im really confused on that too
@@bloxanimates2518 you do keyboard_check_pressed instead of keyboard_check
@@eidy9352 Thats how ya do it
Thanks so much! @eidy and @Hattless Foe
Thank you very much for your videos, Peyton - I just recently got started with GameMaker Studio 2 and your videos have been entertaining, educational and extremely helpful!
thank u than u this was a tutorial i watched for the first time which gave me no errors right away
Amazing, thanks for sharing! I hope you continue to make more! :]
Thank you!
i fixed the switching menu bit by accident and when the fixing for loop bit played i realized i hadnt fixed anything lol
it was torture to get back to the error bit BUT THIS TUTORIAL IS TOOO GOATED
Thanks man, this video really helped, though. I do a have a question, Can you make a part 2 where it covers actually setting up stuff like the volume, reso. etc?
Man, I begg you, make a text box tutorial, you explain things so well and I couldn't find any updated tutorials
I plan on it soon! Just been busy lately but I’m getting it done!
i got a problem. The game is running perfectly, i did everything you said, but when the menu opens, the Menu background sprite isn't there anymore. There's just the big black void behind the text and it looks to me like it's not well-centered like it's supposed to. Can you and the others help me, please?
UPDATE: I found where the problem is coming from. It's the part where you have to position the menu. This part, to be more precise:
width = _new_w + op_border*2;
height = op_border*2 = string_height(option[0, 0]) + (op_length-1)*op_space;
I deleted it and the background menu sprite reappeared, but it looks ugly and it doesn't fit the options nicely. Any ideas on how i can fix it?
Have a good day too!
Great video, thank you so much, this was just the right thing to get me to finally program some menu systems for my games!
I will definitly check you dialogue system too, looking forward to that!
It was very helpful for learning GMS2. much obliged!
If your menu disappears when you add Center Menu code, try dividing it by different values. I had divide my x by 9 and y by 7 to center it. instead of the /2
This series has helped me so much thank you
I got the menu working and all, but for some reason the font I’m using shows up super big and overlaps on each other… anyone know a fix?
Easily understandable and complete, thank you!
Could you do a video on sprint/dash mechanics using the movement script from the rpg series? It'd be really helpful
if keyboard_check(shift_key)
{
move_spd = 2;
}
if keyboard_check_released(shift_key)
{
move_spd = 1;
}
the values of the move speed can be whatever fits your game
Your an actual life saver man with you videos
Great tutorial. Just watched it and gotta have a go on my own now. I also looked up your game. It sounds interesting and I'll have a eye on it. Especially since you also go for a Switch version :)
I'll need your other tutorials too, so, keep going. It'll help to get to know your game to a bigger public.
I love your tutorial series so much. In my opinion, the most helpful one's out there. I really take my time watching them quite thoroughly (I'm a very beginner and need the time to understand it all). I have one open question, maybe someone who reads this find the time to explain it to me.
So we define the position variable in the create-event. (pos = 0). Then, in the step event, we define the current position depending on which buttons we press, and highlight the selected string. My question is: how does GM know from the start, that the pos we defined overlaps with the same position as the first string in our array ? (In this example: "Start Game").
I'm pretty sure I'm overthinking it. But I really want to understand how it works, so I'd be super thankful for any help I'd get here!
I don't speak your language, but if I understood correctly from the translator what your question is, then the gmc initializes what is in create first, and then step, so when it comes to step, the gmc checks pos with option
in the option, the zero cell is equal to "start game" and since the position is 0, then the zero cell will be output, and the zero cell is the start game)
I'm sorry it's so late, but I couldn't help but answer when I saw that the question was unanswered
I love this menu system. For some reason though on my thinner letters like l and i, it leaves a huge space that shouldn’t be there while all the other letters are correctly spaced
Oh my god, I love your tutorials confused why doesn't have more likes
I'm new to coding, I have zero knowledge of it and even tho your videos are basic, I'm still worried if I can understand all of this. Like what's the logic behind those codes? Do I need to understand it first or I just need to follow the tutorial and other tutorials and wait for the day I eventually get it?
If you haven’t watched my “How to make an RPG” series, watch that first, it goes by everything very slowly and i explain how everything works! It’s a bit simpler than this video. At first you’re going to be learning a lot at once so it might feel like you don’t understand, but thats how learning ANY new thing works! Keep following beginner tutorials, pay attention to them very closely, and REWATCH many of them after you’ve finished them. That will help a lot. Soon lots of this stuff will just stick with you and you’ll find your footing! Just keep going!
Hippity Hoppity, Your code is my property!
Great tutorial! - How would I go about adding a little triangle indicator beside the text when cycling through the options?
i second this!! i've been struggling to find an updated gamemaker tutorial about this
In the draw event, you'd do something like: draw_sprite(spr_triangle, 0, x, y+op_border+(op_space*pos)) may need to offset the values depending on your sprite, but this should work
you are a treasure trove good sir. Thank you for these.
HELP, when I try to start the game, it says that, the code "draw_text( x+op_border, y+op_border + op_space*i, opción[i]) it's not set before reading it, can someone tell me how ti fix it ????? 😭😭😭
Came for a menu tutorial, but learned you can have a custom font instead. scuse me as I go figure out how to do that first. xD
This is so great and simple to implement! Thank you!
is there a way to make this menu pop up over the screen and make the game pause with it? If so please make a part 2 to this showing how to code it :)
my code isn't perfect but I have something like this working well enough in my game describing what you're asking. For set up I have 2 instances layers for my game, one with all of the main elements and visuals like the player, obstacles, interactables, etc and one just for holding meta objects. In the step event of an overall controller object, I set up a if key pressed input that would be pausing the game, and use this line that toggles the state of being paused and not:
global.gamePause = -global.gamePause + 1;
then I have an if then statement that says if the game is paused, everything on the main game layer's image speed will be 0 to stop all animations with the instance of the menu being created on a separate layer above (additionally in the player's code if the game is paused, all movement code is stopped). else, the image speed of the main game layer is set back to it's original and the menu instance is destroyed.
There may be a better way to do this or explain this but it's the best I have for now!
I can press spacebar on 'settings' and have it take me to the next menu but when I click "Back" it does not go back to the pause menu. Instead, it takes me into my game as if I had pressed "Start Game."
Has anyone else had this issue, or could possibly guess as to why this might be happening?
Edit:
Never mind. I figured it out.
I had typed accept_key = keyboard_check(vk_space) instead of accept_key = keyboard_check_pressed(vk_space).
So, 'Back' was actually bringing me back to the pause menu, but because the spacebar was still pressed, it would select "Start Game" immediately then I would find myself in my game without ever seeing the pause menu.
Glad you figured it out on your own! It's great to start building that skill of being able to identify little problems like that and knowing what was actually happening! Great work!
I don't know why but I can't for the life of me get the camera centering to work, I've got the
x = camera_get_view_x(view_camera[0]) + camera_get_view_width(view_camera[0])/2 - width/2;
y = camera_get_view_y(view_camera[0]) + camera_get_view_height(view_camera[0])/2 - height/2;
but for whatever reason it disappears whenever I use this code.
I had this issue and it ended up being me forgetting to configure my viewport lol
Make sure U enabled viewport, make viewport 0 visible, configure your camera properties height and width and viewport properties width and height to whatever your games properties are and have the camera follow the obj_tile_menu (or whatever you chose to call your menu object) and it should show up when you run the game 👍
POV : you watch that hole Tutorial from 10 PM to 1:30 PM ... gn
These guides need text docs, scrubbing through when things don't run is a pain
why are my texts gibbirish? Like Start Game is like Tubsu Gbnf?
Fixed my problem: I missed a character on my font. Be sure to not miss one or else it'll go chaotic.
tubsu gbnf, words i will never forget lol!
I did the same thing, missed the speech marks when making the font
I'm having a small problem where when i select "back" to return to the main menu, it imediatly selects the top option, and i have no idea why
I had the same issue, the problem was I forgot to put "break;" in the switch(menu_level) cases.
@@Busterbrown1902 Turns out it was something way stupider
instead of "Keyboard_check_pressed(vk_space)"
I had put "Keyboard_check(vk_space)"
Great video! But I still have a few questions. How would I go about making 2 more submenus? I tried just essentially following all the steps again creating 2 more cases. But my new submenues only have 2 cases in them each. But for some reasong when I try to open them it gives me an error. Saying there was something wrong on my Draw event 12, this one, draw_text_color(x+op_border, y+op_border + op_space*i, option[menu_level, i], _c, _c, _c, _c, 1);
If you ever figured it out can you let me know, hitting the same error message and can't seem to figure it out...
You need to update your op_length variable when switching to a smaller menu(in your example a menu with 2 cases), let's say that the main menu has three cases, when you switch into your smaller submenu without updating op_length, gamemaker remembers that op_length is three so when it's trying to draw the submenu it returns an error because there is no 3rd case.
Here's my code in the step event in case you don't understand:
//Check for accept input
if acceptK
{
//Switch pos
switch menuLevel
{
//Main menu
case 0:
switch pos
{
case 0: room_goto_next(); break;
case 1: menuLevel = 1; break;
case 2: menuLevel = 2; opLen = menuLevel; break; //Updating opLen to current menu level
case 3: game_end(); break;
}
break;
//Options menu
case 1:
switch pos
{
case 0: break;
case 1: break;
case 2: break;
case 3: menuLevel = 0; break;
}
break;
//About menu
case 2:
switch pos
{
case 0: break;
case 1: menuLevel = 0; break;
}
break;
}
}
Sorry for late response and I hope this helps :)
Damn. Thanks for Tutorial. Your demo is windows only sadly which I only have m1 Mac which does not allow for bootcamp :(
Congrats though on the kickstarter for 15K.
I'm running into a few problems while doing it. First of all, the object I put in the room is very small when I run it. What should I do? and finally, can we get the font ready instead of creating it ourselves?
Same issue here. could you fix it?
i met the same problem, have you resolved it?
1. just put object in the room, dont stretch It :)
2. create font(right click on workspace>assets>create font), name it font_main(or whatever you want), then in obj_settings create event instead of tutorial code put these code: global.font_main = font_main;
@@Wakakakakaku how would i type this code for the clean up would it be
it says
idk what im doing wrong anytips?
trying to delete non-existing font.
at gml_Object_Obj_settings_CleanUp_0 (line 1) - font_delete(global.font_text);
why does my menu vanishes when i use that one last code (setting the center menu part)? I believe i did everything as the video shown
//center menu
x = camera_get_view_x(view_camera[0]) + camera_get_view_width(view_camera[0])/2 - width/2
y = camera_get_view_y(view_camera[0]) + camera_get_view_height(view_camera[0])/2 - height/2
i got this error
ERROR in
action number 1
of Create Event
for object oSetting:
global variable name 'font' index (100030) not set before reading it.
at gml_Object_oSetting_Create_0 (line 1) - global.font.main = font_add_sprite(xxxfont, 32, true, 1)
how do i fix it?
Remove global and just write "draw_set_font(font_main);" instead. That's what worked for me.
I keep entering a code error whenever I try to load up my game. The issue is with the 5th line of code in obj_settings and create. It keeps saying that font_main is not established and idk what to do :(
What happens if you don't want to use a custom font or if you just want to use a downloaded font?
just write the font you have in the "draw_set_font();" line and don't add the custom part :D
@@KokomiFish0oh my god thank you so much your a doll😭😭
I'll be trying this out! Thank you! However, I feel it's easier to use the Draw GUI event.
this repeating whistling song is driving me crazy
the background on my menu seemingly duplicated itself without its animation behind the first one (that has the animation) and the second one is wider than the first, anyone know how to fix this?
This very helpful, thank you a lot!
If you've been having trouble with deformed sprites like I have, here's a workaround.
Simply change the Tile Mode of each part of the sprite's Nineslice to Repeat.
what if the next menu level has less options than the first menu level? I kinda merged your video and shaun spalding's, I have a little arrow to show what you're selecting as well as colour. But yeah I have that error. Here's my draw code, the error is "var txt = menu[menuLevel, i]"
for (var i = 0; i < menuItems; i++)
{
var offset = 2;
var txt = menu[menuLevel, i];
I think I'm having the same issue as you. Did you ever figure it out?
@@KingOfFoolz no sadly I did not. I kinda gave up on it lol but there has to be some sort of solution
Can you please do a tutorial for text boxes and how did you do the text box that was in the end of part 6
Yep I'm still planning on doing it! I have it outlined and everything I just need to find some time in the next few days to record and edit it!
@@peytonburnham4316 and whenever will you do it iam waiting for you bro
Quick question regarding the initial length and width values.
In the beginning of the tutorial you set width and height values for the menu border and later on you made the menu border size dependent on the text and fonts.
Would the initial length and width values still matter? Or could you just set them to 0 and let the step event change them dynamically according to what’s being displayed?
I chaged them to 0 and it seems to work fine so I think it's ok to initialize them all at 0.
Hi There Peyton, followed your tutorial to the dot! The difficulty skyrockets in this one compared to your 6-part series. I love your tutorials so far! they are really helpful!
I managed to make the menu work as intended but with a few problems:
1st of all I do not know how to adjust the height and width of the box and letters to make them appear a bit bigger compared to the screen and 2nd when I click on "back" on the settings menu the game crashes and it returns the following error:
############################################################################################
ERROR in
action number 1
of Draw Event
for object obj_title_menu:
Variable Index [3] out of range [3]
at gml_Object_obj_title_menu_Draw_0 (line 5) - var _op_w = string_width(option[menu_level, i]);
############################################################################################
gml_Object_obj_title_menu_Draw_0 (line 5)
Thanks again in advance! Keep up the awesome work!!
I'm having this same issue with the menu options. The only way it works for me currently is if both menus have the same amount of choices. My best guess is because arrays now only come in 1D, no longer 2d, technically.
i'll help u
STEP EVENT
//get inputs
up_key = keyboard_check_pressed(vk_up);
down_key = keyboard_check_pressed(vk_down);
accept_key = keyboard_check_pressed(vk_enter);
//store number of options in current menu;
op_length = array_length(option[menu_level]);
//move through the menu
pos += down_key - up_key;
if pos >= op_length {pos = 0};
if pos < 0 {pos = op_length-1};
//using the options
if accept_key {
var _sml = menu_level;
switch(menu_level) {
//pause menu
case 0:
switch(pos) {
//start game
case 0: room_goto_next(); break;
//settings
case 1: menu_level = 1 break;
//quit game
case 2: game_end(); break;
}
break;
//settings
case 1:
switch(pos) {
//window size
case 0:
break;
//brightness
case 1:
break;
//controls
case 2:
break;
//back
case 3:
menu_level = 0;
break;
}
break;
}
//set position back
if _sml != menu_level {pos = 0};
//correct option length
op_length = array_length(option[menu_level]);
}
CREATE EVENT
width = 64;
height = 104;
op_border = 8;
op_space = 16;
pos = 0;
//pause menu
option[0, 0] = "Start Game";
option[0, 1] = "Settings";
option[0, 2] = "Quit Game";
//settings menu
option[1, 0] = "Window Size";
option[1, 1] = "Brightness";
option[1, 2] = "Controls";
option[1, 3] = "Back";
option[2, 1] = "select";
op_length = 0;
menu_level = 0;
DRAW EVENT
//dynamically get width and height of menu
var _new_w = 0;
for (var i = 0; i < op_length; i++)
{
var _op_w = string_width(option[menu_level, i]);
_new_w = max(_new_w, _op_w);
}
width = _new_w + op_border*2;
height = op_border*2 + sprite_get_height(spr_main_font) + (op_length-1)*op_space;
//center menu
x = camera_get_view_x(view_camera[0]) + camera_get_view_width(view_camera[0])/2 - width/2;
y = camera_get_view_y(view_camera[0]) + camera_get_view_height(view_camera[0])/2 - width/2;
//draw the menu background
draw_sprite_ext(sprite_index, image_index, x, y, width/sprite_width, height/sprite_height, 0, c_white, 1);
//draw the options
draw_set_font(global.font_main);
draw_set_valign(fa_top);
draw_set_halign(fa_left);
for (var i = 0; i < op_length; i++)
{
var _c = c_white;
if pos == i {_c = c_yellow};
draw_text_color(x+op_border, y+op_border + op_space*i, option[menu_level, i], _c, _c, _c, _c, 1);
}
I excuse in advance for bad English
If your viewport has a number but the window resolution has an higher one (something like the viewport being 288x216 and the window being 864x648) and you're trying to make a pixel art game then you might have a problem, the pixels will have a bad scale due to the width being a odd number, to resolve that problem, add this line:
if _new_w%2 == 1 {_new_w += 1};
It will check if it's an odd number, then add 1 to the variable to make it an even one
Is there any way to use the sprites that come in with GM2 rather than making your own? I really like the look of MS Gothic and I want to find a way to use that instead, but it's just a font. Not a sprite.
Thank you for the tutorial, it's really well made. I need help please; I've been trying to find a way to make a pause menu like in the beginning of the video with but it keeps telling me that op_length isn't set before being read. Here's my code :
In the step even of the player object:
pause_key = keyboard_check(vk_escape);
if pause_key = 1
{
instance_create_layer(0, 0, "Instances", obj_pause_menu);
}
I haven't made any code to remove the instance yet because I'm not able to create it in the first place.
I'd really appreciate any help, thanks.
remove the "= 1" from the if statement. also when checking for things in if statements, you must use two equal signs. one equal sign means that you are setting the value of something, and two equal signs are how you check for the value of something inside a conditional (which is if statements, while statements, etc.). also the pause_key variable would be a boolean, which is true or false. checking if it's equal to one wont work because one is an integer, and pause_key is not an integer value. you would use if pause_key == true. however, that is unnecessary when checking if a boolean is true. hope this helps and was informative for you, id recommend watching some coding basics tutorials. learning things in once language can translate to all languages, even with syntax differences theres universal things that you need to know in coding
Great tutorial overall, loved it! Just one question, how would I add a sound effect every time I switch to a new option?
I’m not the video poster, but in the step event within the input checks, where there are two if loops under “//move through the menus”, you could put an audio play in each of those loops.
probably you already solved but I went this route work pretty well right now.
if up_key
{
audio_play_sound(sound,1,0)
}
and same for the down key
This man is reason why ww3 never started!