J
Jamonnin
Guest
I've tried setting coordinates using room width and height, as well as a few other methods. I've been googling for 2 hours and cannot find an efficient way to center drawn text onto the screen no matter the android device.
I already tried this and it didn't work..Moving to Programming.
Take a look at draw_set_halign in the manual.
One of the most important rules of asking for help is to never say "doesn't work". Interpret an urge to say that as a clear sign that you need to provide more information, including but not limited to what you tried, what you expected to happen and what happened instead.I already tried this and it didn't work..
/// draw_text_gui_hcentre(offset, yy, h_align, v_align, str)
/*
* example use:
* Draw GUI event:
* draw_text_gui_hcentre(0, 0, fa_center, fa_top, "This text is in the top centre of the GUI");
*/
{
var offset, yy, h_align, v_align, str;
offset = argument0;
yy = argument1;
h_align = argument2;
v_align = argument3;
str = argument4;
var centre_x, xx;
centre_x = 0.5*display_get_gui_width();
xx = centre_x + offset;
draw_set_halign(h_align);
draw_set_valign(v_align);
draw_text(xx, yy, str);
}
Very good point. Usually I would, I was just frustrated because I spent 5-7 hours creating a menu system I would use for all my games, and ended up just scrapping it because of one tiny detail that was fixable. Very stupid thing to do. Thanks for the help.One of the most important rules of asking for help is to never say "doesn't work". Interpret an urge to say that as a clear sign that you need to provide more information, including but not limited to what you tried, what you expected to happen and what happened instead.
I'll try a few variations of this now, thank you!Here's a script that does what @The Reverend suggested:
Code:/// draw_text_gui_hcentre(offset, yy, h_align, v_align, str) /* * example use: * Draw GUI event: * draw_text_gui_hcentre(0, 0, fa_center, fa_top, "This text is in the top centre of the GUI"); */ { var offset, yy, h_align, v_align, str; offset = argument0; yy = argument1; h_align = argument2; v_align = argument3; str = argument4; var centre_x, xx; centre_x = 0.5*display_get_gui_width(); xx = centre_x + offset; draw_set_halign(h_align); draw_set_valign(v_align); draw_text(xx, yy, str); }
draw_set_halign(fa_center);
draw_set_valign(fa_top);
var test1 = display_get_gui_width();
var test2 = view_wview[0];
var test3 = room_width;
//scr_draw_text_outline(display_get_gui_width() / 2, display_get_gui_height() / 2, 5, "test1");
//scr_draw_text_outline(view_wview[0] / 2, view_hview[0] / 3, 5, "test2");
//scr_draw_text_outline(room_width / 2, room_height / 2, 5, "test3");
draw_text(display_get_gui_width() / 2, 128, test1);
draw_text(view_wview[0] / 2, 360, test2);
draw_text(room_width / 2, 720, test3);
display_set_gui_maximise(); // would normally call only once i.e. in create event
xx = display_get_gui_width() / 2;
draw_set_halign(fa_center);
txt = string(display_get_gui_width());
draw_set_font(fnt_small);
draw_text(xx, 128, txt);
draw_set_font(fnt_large);
draw_text(xx, 256, txt);
draw_set_font(fnt_huge);
draw_text(xx, 512, txt);
draw_set_font(-1);
That's strange. I honestly don't know what to say. I don't have to go above 96 pts so I'm just moving on for now. Thanks for the helpI couldn't reproduce that behaviour. Had this in Draw GUI event:
Where fnt_huge was a pt 192 font and was still centered.Code:display_set_gui_maximise(); // would normally call only once i.e. in create event xx = display_get_gui_width() / 2; draw_set_halign(fa_center); txt = string(display_get_gui_width()); draw_set_font(fnt_small); draw_text(xx, 128, txt); draw_set_font(fnt_large); draw_text(xx, 256, txt); draw_set_font(fnt_huge); draw_text(xx, 512, txt); draw_set_font(-1);
Also tested with two fonts: arial and venus rising.
Tested on different window sizes: 768p & 1080p.
It was always working as expected.