How to fix centering my drawn menu with for loop

R

RealsLife

Guest
I've a pixelart game so I've made a pixel perfect script which works.

the viewport stays the same.
If I push 0,1,2,3 the view changes so the viewport is upscalling correctly.

However when I tried to center my for loop drawn menu.

draw_set_halign(fa_center);
draw_set_halign(fa_middle);

these didn't do much

I tried view_wview[0]/2 for the width and view_hview[0]/2 for the height but they didn't center the menu :(

so in the end it worked with room_width/2 and room_height/2 but this isn't the right way to fix this because
this works only because it is just a menu but it would not work for a GUI for example when a character runs around.

I want to know why the menu didn't center, if someone could explain please I love game maker studio and want to learn as much as I can :O!

After this the main menu is 100% finished code wise hehe :D!
 

Tthecreator

Your Creator!
btw, draw_set_halign is ONLY for use with text.

If you want to center the menu, you'll have to get the center of you screen which you can get by using:
centerx=view_xview[0]+view_wview[0]/2. Here, we are adding the x coordinate of the left-top of the screen, and adding halve the views size with it. (may sound confusing) You were just getting the middle point of view and not of your entire room.

What i'd recommend anyways is looking into the draw gui event, as it ignores all views and scaling like that, and just draws to you screen whenever everything else has been drawn. If you are using that you can use window_get_width()/2 and window_get_height()/2 to get your center coordinates.

Another pitfall for you is that you can get the center of the screen, but you want to make your menu centered around that point, not make the left-top point of the menu the center of the screen. If you are having trouble with that, you first have to know the width and height of your menu, and divide these numbers, then substract them from your "center point".
 
R

RealsLife

Guest
btw, draw_set_halign is ONLY for use with text.

If you want to center the menu, you'll have to get the center of you screen which you can get by using:
centerx=view_xview[0]+view_wview[0]/2. Here, we are adding the x coordinate of the left-top of the screen, and adding halve the views size with it. (may sound confusing) You were just getting the middle point of view and not of your entire room.

What i'd recommend anyways is looking into the draw gui event, as it ignores all views and scaling like that, and just draws to you screen whenever everything else has been drawn. If you are using that you can use window_get_width()/2 and window_get_height()/2 to get your center coordinates.

Another pitfall for you is that you can get the center of the screen, but you want to make your menu centered around that point, not make the left-top point of the menu the center of the screen. If you are having trouble with that, you first have to know the width and height of your menu, and divide these numbers, then substract them from your "center point".
Ah nice! I tried somthing similar which didn't result in the center but like somthing close but now I know why! Thanks for the info :D!
 
R

RealsLife

Guest
Okaaay so I've 2different objects pixel perfect and main_menu. The menu apparently works fine(if I put it alone in a room) it's the pixel perfect script who 💩💩💩💩s everything up.

What that object does is I push 0,1,2,3 -> viewport is a fixed value the view changes with the push of the numbers.

IN THE PIXEL PERFECT OBJECT In the draw event:
surface_resize(application_surface, view_wport[0],view_hport[0]);
display_reset(0,false);
window_set_size(view_wport[0],view_hport[0]);

Like you said I could use GUI but why is it not working in the normal draw event o_O?

IN THE MAIN MENU in the draw event:
//set position text & font & color
draw_set_halign(fa_center);
draw_set_halign(fa_middle);
draw_set_font(fnt_standard);

centerx=view_xview[0]+view_wview[0]/2

for(i = 0; i < array_length_1d(menu); i += 1)
{
draw_set_color(c_gray);
if(i == selection){draw_set_color(c_black);}
draw_text(centerx,room_height/2+(i * space),string(menu))
}
menu.png
 
Top