Hud bar in the top left corner and scale to screen / window size

skofrant

Member
Hi,
I would like the HUD bar to scale to the size of the window. Currently, when I start the game in the window, the HUD bar is the same size as in the full game screen
The HUD bar is located in the upper left corner of the screen.

there are lots of sprites and text in the hud bar. I don't know if to use the function here

GML:
display_get_gui_width
something will help ... because it's not just one sprite and one text on the strip
can I use the surface function? but I do not know what it would look like in its final form

once the HUD bar only had a sprite of energy nothing more and it scaled , now it's quite extensive and I don't want to scale anymore
even here I have used such values before

GML:
var __guiW = display_get_gui_width(), __guiH = display_get_gui_height();

thank you for any help ..


global_controler

draw_gui


GML:
///HUD


var __guiW = display_get_gui_width(), __guiH = display_get_gui_height();
draw_sprite(spr_hp_bar,0,x+25,70);


draw_sprite_ext( spr_HUD, 0, x+145, y-10, 1, 1, 0, -1, 0.5 );

//life
draw_set_color(c_white);
draw_set_valign(fa_middle);
draw_set_halign(fa_center);
draw_set_font(font_hud);
draw_sprite(spr_life,1,340,70);
draw_text(340,105,string("x" + string(global.life)));
draw_text(340, 25,"lives");


//points
draw_set_color(c_white);
draw_set_valign(fa_middle);
draw_set_halign(fa_center);
draw_set_font(font_hud);
draw_sprite(spr_score,1,410,70);
draw_text(410, 105, ""+string(global.scores));
draw_text(410, 25,"scores");


//coins
draw_set_color(c_white);
draw_set_valign(fa_middle);
draw_set_halign(fa_center);
draw_set_font(font_hud);
draw_sprite(spr_coins,1,480,70);
draw_text(480, 105,string("$" + string(global.coins)));
draw_text(480, 25,"coins");



// 5 types of hero weapons to choose from .... displayed in one sprite
draw_set_color(c_white);
draw_set_valign(fa_middle);
draw_set_halign(fa_center);
draw_set_font(font_hud);
draw_sprite(spr_weapons,current_weapon,560,70); // draw a sprite of weapons



draw_set_color(c_white);
draw_set_valign(fa_middle);
draw_set_halign(fa_center);
draw_set_font(font_hud);


var i = current_weapon;
{
if !(i = 0)



draw_text(560,105,""+string(global.wep[i,e_wep.ammo])); // the number of ammunition
draw_text(560,25,""+string(global.wep[i,e_wep.name])); // drawing the name of the weapon

}





draw_set_color(c_white);
draw_set_valign(fa_middle);
draw_set_halign(fa_center);
draw_set_font(font_hud);
draw_text(190, 25,"hp bar");




//HP HUD

if instance_exists(par_player) {


hpHUD=global.hp;
maxHpHUD = par_player.maxHp;


//HUD Powerup

with obj_player {
  var _offset;
  _offset = 0;

  draw_set_font(fnt_pwrup);
  draw_set_valign(fa_bottom);
  draw_set_halign(fa_center);
  draw_set_color(c_white);
  draw_texture_flush();

  if pwrupSpd > 0 {
   draw_sprite_ext(spr_pwrup_speed,0,__guiW-26,29+35*_offset,1,1,0,c_gray,.5);
   draw_text(__guiW-26,29+35*_offset,string(ceil(pwrupSpd/room_speed)));
   _offset++;
  }
  if pwrupStr > 0 {
   draw_sprite_ext(spr_pwrup_strength,0,__guiW-26,35+35*_offset,1,1,0,c_gray,.5);
   draw_text(__guiW-26,35+35*_offset,string(ceil(pwrupStr/room_speed)));
   _offset++;
  }
  if pwrupJmp > 0 {
   draw_sprite_ext(spr_pwrup_jump,0,__guiW-26,28+35*_offset,1,1,0,c_gray,.5);
   draw_text(__guiW-26,28+35*_offset,string(ceil(pwrupJmp/room_speed)));
   _offset++;
  }
}
} else {
hpHUD = lerp(hpHUD,0,.5);
}

//HUD life


draw_sprite_part(spr_hp_bar,1,1,0,225/maxHpHUD*hpHUD,130,88,48);
draw_set_color(c_white);
draw_set_valign(fa_middle);
draw_set_halign(fa_center);
draw_set_font(font_hud);
draw_sprite(spr_head,1,60,70);
 

Yal

šŸ§ *penguin noises*
GMC Elder
GML:
display_set_gui_size(640,360)
Now the GUI layer is 640 x 360 pixels. If the window is larger than that, those 640x360 pixels are stretched to cover the entire window, and everything just magically gets scaled without you having to manually add scaling factors everywhere.
 

skofrant

Member
GML:
display_set_gui_size(640,360)
Now the GUI layer is 640 x 360 pixels. If the window is larger than that, those 640x360 pixels are stretched to cover the entire window, and everything just magically gets scaled without you having to manually add scaling factors everywhere.

ok half of my view.. I understand
so it's enough that I set this function at the beginning of my code in draw GUI and the scaling will automatically work to the values given in the function?


draw GUI

GML:
///HUD


display_set_gui_size(640,360)
  

//var __guiW = display_get_gui_width(), __guiH = display_get_gui_height();
draw_sprite(spr_hp_bar,0,x+25,70);


draw_sprite_ext( spr_HUD, 0, x+145, y-10, 1, 1, 0, -1, 0.5 );

//life
draw_set_color(c_white);
draw_set_valign(fa_middle);
draw_set_halign(fa_center);
draw_set_font(font_hud);
draw_sprite(spr_life,1,340,70);
draw_text(340,105,string("x" + string(global.life)));
draw_text(340, 25,"lives");


//points
draw_set_color(c_white);
draw_set_valign(fa_middle);
draw_set_halign(fa_center);
draw_set_font(font_hud);
draw_sprite(spr_score,1,410,70);
draw_text(410, 105, ""+string(global.scores));
draw_text(410, 25,"scores");


//coins
draw_set_color(c_white);
draw_set_valign(fa_middle);
draw_set_halign(fa_center);
draw_set_font(font_hud);
draw_sprite(spr_coins,1,480,70);
draw_text(480, 105,string("$" + string(global.coins)));
draw_text(480, 25,"coins");



// 5 types of hero weapons to choose from .... displayed in one sprite
draw_set_color(c_white);
draw_set_valign(fa_middle);
draw_set_halign(fa_center);
draw_set_font(font_hud);
draw_sprite(spr_weapons,current_weapon,560,70); // draw a sprite of weapons



draw_set_color(c_white);
draw_set_valign(fa_middle);
draw_set_halign(fa_center);
draw_set_font(font_hud);


var i = current_weapon;
{
if !(i = 0)



draw_text(560,105,""+string(global.wep[i,e_wep.ammo])); // the number of ammunition
draw_text(560,25,""+string(global.wep[i,e_wep.name])); // drawing the name of the weapon

}





draw_set_color(c_white);
draw_set_valign(fa_middle);
draw_set_halign(fa_center);
draw_set_font(font_hud);
draw_text(190, 25,"hp bar");




//HP HUD

if instance_exists(par_player) {


hpHUD=global.hp;
maxHpHUD = par_player.maxHp;


//HUD Powerup

with obj_player {
  var _offset;
  _offset = 0;

  draw_set_font(fnt_pwrup);
  draw_set_valign(fa_bottom);
  draw_set_halign(fa_center);
  draw_set_color(c_white);
  draw_texture_flush();

  if pwrupSpd > 0 {
   draw_sprite_ext(spr_pwrup_speed,0,__guiW-26,29+35*_offset,1,1,0,c_gray,.5);
   draw_text(__guiW-26,29+35*_offset,string(ceil(pwrupSpd/room_speed)));
   _offset++;
  }
  if pwrupStr > 0 {
   draw_sprite_ext(spr_pwrup_strength,0,__guiW-26,35+35*_offset,1,1,0,c_gray,.5);
   draw_text(__guiW-26,35+35*_offset,string(ceil(pwrupStr/room_speed)));
   _offset++;
  }
  if pwrupJmp > 0 {
   draw_sprite_ext(spr_pwrup_jump,0,__guiW-26,28+35*_offset,1,1,0,c_gray,.5);
   draw_text(__guiW-26,28+35*_offset,string(ceil(pwrupJmp/room_speed)));
   _offset++;
  }
}
} else {
hpHUD = lerp(hpHUD,0,.5);
}

//HUD life


draw_sprite_part(spr_hp_bar,1,1,0,225/maxHpHUD*hpHUD,130,88,48);
draw_set_color(c_white);
draw_set_valign(fa_middle);
draw_set_halign(fa_center);
draw_set_font(font_hud);
draw_sprite(spr_head,1,60,70);
 
Last edited:

skofrant

Member
I think that's not the point ... I mean that when I want to run the game, for example, in windowed mode, the HUD bar should scale to the size of the window ... because now, when I run the window mode, the HUD bar has the same dimensions what full screen ..
your solution causes that in full screen I have an "even bigger hud bar" in full screen it has to remain as it is
I mean window mode..here it should automatically ..that scales to the size of the game window
 

skofrant

Member
He tries this way for example ..
but I don't know if it will work because I haven't checked yet
The HUD bar and the elements on it should scale to the size of the window.

GML:
draw_set_color(c_white);
draw_set_valign(fa_middle);
draw_set_halign(fa_center);
draw_set_font(font_hud);
draw_sprite(spr_life,1, display_get_gui_width()+340,display_get_gui_height()+70);
draw_text(display_get_gui_width()+340,display_get_gui_height()+105,string("x"+string(global.life));
draw_text( display_get_gui_width()+340, display_get_gui_height()+25"lives");
 

Tony Brice

Member
You only need to set the gui window size once, unless you're changing it somewhere else, which is pretty unlikely.

Code:
display_set_gui_size(640,360)
Should go into your create event rather than the draw event, as it's trying to do it 60 times a second otherwise. Possibly it doesn't affect it and gets ignored, if it's that size already, but I'd still change it, just in case.
 

skofrant

Member
You only need to set the gui window size once, unless you're changing it somewhere else, which is pretty unlikely.

Code:
display_set_gui_size(640,360)
Should go into your create event rather than the draw event, as it's trying to do it 60 times a second otherwise. Possibly it doesn't affect it and gets ignored, if it's that size already, but I'd still change it, just in case.

yes, but once I set the size of the GUI window, when I run the game my HUD bar takes up almost the entire screen in full screen .. so something is wrong ..
 

skofrant

Member
You only need to set the gui window size once, unless you're changing it somewhere else, which is pretty unlikely.

Code:
display_set_gui_size(640,360)
Should go into your create event rather than the draw event, as it's trying to do it 60 times a second otherwise. Possibly it doesn't affect it and gets ignored, if it's that size already, but I'd still change it, just in case.

it doesn't help .. in create or draw wherever I put this function. HUD bar is big .. even bigger than it was before ..
 

skofrant

Member
ok now it's good ... it turned out that I had the wrong values ... the game starts in 1920x1080 and then scales to 1280x720

on these values it's okay ..



create

GML:
display_set_gui_size(960,540)

There is only one small problem .. For one time let's assume for 4.5, 10 when I restart the game the HUD bar is big again .... Anyone can tell me what is the reason for this? strange situation because I run the game several times it's all right..and after some time the HUD bar gets bigger..Then just I restart the game and it's fine
 

skofrant

Member
I think the problem lies elsewhere
the game the scales to any size, while the HUD bar and the objects placed on them do not want to scale .. No matter if I set the window or fullscreen mode, this HUD sprite and all its content is the same large

this function does not help and no matter what values i set here ..


GML:
display_set_gui_size(960,540)



exactly these items below don't want to scale to any window size ..

I have tried to use such a solution before but it doesn't help either

GML:
display_set_gui_size(display_get_gui_width()/2,display_get_gui_height()/2)


As to switch to windowed mode, the HUD bar should be half the size of the fullscreen mode ... and so are all sprites and text is located draw gui event






draw GUI

GML:
draw_sprite(spr_hp_bar,0,x+25,70);


draw_sprite_ext( spr_HUD, 0, x+145, y-10, 1, 1, 0, -1, 0.5 );

//life
draw_set_color(c_white);
draw_set_valign(fa_middle);
draw_set_halign(fa_center);
draw_set_font(font_hud);
draw_sprite(spr_life,1,340,70);
draw_text(340,105,string("x" + string(global.life)));
draw_text(340, 25,"lives");


//points
draw_set_color(c_white);
draw_set_valign(fa_middle);
draw_set_halign(fa_center);
draw_set_font(font_hud);
draw_sprite(spr_score,1,410,70);
draw_text(410, 105, ""+string(global.scores));
draw_text(410, 25,"scores");


//coins
draw_set_color(c_white);
draw_set_valign(fa_middle);
draw_set_halign(fa_center);
draw_set_font(font_hud);
draw_sprite(spr_coins,1,480,70);
draw_text(480, 105,string("$" + string(global.coins)));
draw_text(480, 25,"coins");



// 5 types of hero weapons to choose from .... displayed in one sprite
draw_set_color(c_white);
draw_set_valign(fa_middle);
draw_set_halign(fa_center);
draw_set_font(font_hud);
draw_sprite(spr_weapons,current_weapon,560,70); // draw a sprite of weapons



draw_set_color(c_white);
draw_set_valign(fa_middle);
draw_set_halign(fa_center);
draw_set_font(font_hud);


var i = current_weapon;
{
if !(i = 0)



draw_text(560,105,""+string(global.wep[i,e_wep.ammo])); // the number of ammunition
draw_text(560,25,""+string(global.wep[i,e_wep.name])); // drawing the name of the weapon

}





draw_set_color(c_white);
draw_set_valign(fa_middle);
draw_set_halign(fa_center);
draw_set_font(font_hud);
draw_text(190, 25,"hp bar");



//HUD life


draw_sprite_part(spr_hp_bar,1,1,0,225/maxHpHUD*hpHUD,130,88,48);
draw_set_color(c_white);
draw_set_valign(fa_middle);
draw_set_halign(fa_center);
draw_set_font(font_hud);
draw_sprite(spr_head,1,60,70);
 
Last edited:
Top