AdriandotEXE
Member
Hey everyone,
I am trying to create a customized menu as a separate object, however, the code in the object is not working. It should show a list of text options as the you'll see in the code below, however, currently it shows a black screen. Previously, the menu was drawn as a non-interactive sprite and existed in a controller object labeled o_game, but I erased it because I found it to be more difficult to code within that object. After I erased the code in o_game, I made an object dedicated solely to the menu and placed it into a room exclusively for the menu. I made sure that o_menu was in the room and I tried running it in a newly created project file; neither of these attempts ran the code and created the menu. Am I going about this the wrong way? Can I create the same custom menu I previously had in o_game? Is there anything in o_game that could possibly obstruct the menu from being created. It should be noted I have room with o_game and the camera that loads before the menu room.
o_game draws the menu as an image like so:
o_menu:
UPDATE: Using the Draw GUI event instead of the regular Draw event produces the text, although it isn't aligned properly, it is progress.
I am trying to create a customized menu as a separate object, however, the code in the object is not working. It should show a list of text options as the you'll see in the code below, however, currently it shows a black screen. Previously, the menu was drawn as a non-interactive sprite and existed in a controller object labeled o_game, but I erased it because I found it to be more difficult to code within that object. After I erased the code in o_game, I made an object dedicated solely to the menu and placed it into a room exclusively for the menu. I made sure that o_menu was in the room and I tried running it in a newly created project file; neither of these attempts ran the code and created the menu. Am I going about this the wrong way? Can I create the same custom menu I previously had in o_game? Is there anything in o_game that could possibly obstruct the menu from being created. It should be noted I have room with o_game and the camera that loads before the menu room.
o_game draws the menu as an image like so:
GML:
//Draw
//720x360
//get gui dimensions
var gw = display_get_gui_width();
var gh = display_get_gui_height();
//draw main menu and fade to first level
//draw bounce
var start_y = 350; //how far the animation moves
var factor = start_y;
var max_frames = 60; //how long animation goes for
if current_frame < max_frames {
current_frame++;
var move = EaseOutBounce(current_frame, 0, 1, max_frames)
} else {
move = 1;
//alow game start as menu has dropped
if (keyboard_check_pressed(vk_space) or gamepad_button_check_pressed(0, gp_face1)) and
!instance_exists(o_fade) {
//move to the next room on the list
//get string of the next room i.e. "rm_01"
//var next_room_str = room_get_name(room_next(room));
//get asset index of next room i.e 1, 2, 3...rooms start at 0
//var next_room_name = asset_get_index(next_room_str);
fade_to_room(room_next(room), 0, 0, 1, c_black);
}
}
draw_sprite(s_main_menu, 0, 0, (move * factor) - start_y);
//draw highscore
if current_frame == max_frames {
draw_set_halign(fa_right);
draw_set_font(fnt_bookman);
draw_text_ext_colour(gw - 10, 28, highscore, 5, 100, c_aqua, c_aqua, c_gray, c_gray, 1);
}
}
//fade screen in
if fade_in {
alpha = lerp(alpha, 0, fade_spd);
draw_set_alpha(alpha);
draw_rectangle_colour(0, 0, gw, gh, c_black, c_black, c_black, c_black, false);
draw_set_alpha(1);
}
//display msg
if alarm[DISPLAY_MSG] > 0 {
draw_set_halign(fa_center);
draw_set_font(fnt_bookman);
draw_set_color(c_black);
draw_text(gw/2 + 1, gh *.85 + 1, msg);
draw_set_color(c_white);
draw_text(gw/2, gh *.85, msg);
}
GML:
//Create Event
//main menu
menu[0] = "Start";
menu[1] = "Options";
menu[2] = "Exit";
index = 0;
//Step
// get input
var _up = keyboard_check_pressed(vk_up);
var _down = keyboard_check_pressed(vk_down);
var _select = keyboard_check_pressed(vk_enter) or keyboard_check_pressed(vk_space);
var _move = _down - _up;
if _move !=0 {
//move index
index += _move
//clamp values
var _size = array_length_1d(menu);
if index < 0 index = _size - 1;
else if index >= _size index = 0;
}
//Draw
draw_set_halign(fa_center);
draw_set_font(fnt_menu);
//line spacing
var _ gap = 40;
//draw items
for(var i = 0; i < array_length_1d(menu); ++i ) {
draw_set_color(c_white);
if i == index draw_set_color(c_teal);
draw_text(room_width/2, room_height * 0.4 + _gap *i, menu[i]);
}
UPDATE: Using the Draw GUI event instead of the regular Draw event produces the text, although it isn't aligned properly, it is progress.
Last edited: