User HUD/GUI

Alexir

Member
I have a top-down shoot 'em up game, and I am trying to figure out how to set up such things as a health bar, progress bar, etc. The problem I have isn't with programming these displays to work properly, it's that I don't know how to make them stay in the same place on the screen. My previous solution was since the player was always in the middle of the screen, I would just make the health bar's coordinates relative to the player, but in my newest project, the player isn't always in the middle of the screen. I've done some research with viewports and Draw GUI events but I am still lost. I am using GameMaker language, and any ounce of help would be much appreciated.
 

woods

Member
i still fight with image_xview and image_hview[0] and the differences between them..

this might point you in a forward direction at least ;o)

here's an example of a controller object in my latest project.. its a 2player, splitscreen, PvP spaceshooter.
i am drawing player stats to the top left corner of their respective views..

Code:
/// draw players stats

if (room == rm_start)
{
//P1
if (view_current == 0)
    {
    draw_text_transformed(view_xview[0], view_yview[0], "HP " + string(obj_P1.HP),4,4,0); // draw P1 HP
    draw_text_transformed(view_xview[0], view_yview[0]+64, "FIRE " + string(obj_P1.countdown),3,3,0); // draw P1 ready to fire
    draw_text_transformed(view_xview[0], view_yview[0]+96, "turn " + string(obj_P1.turn_spd),3,3,0); // draw P1 turn spd
    draw_text_transformed(view_xview[0], view_yview[0]+128, "thrust " + string(obj_P1.thrust),3,3,0); // draw P1 thrust
    draw_text_transformed(view_xview[0], view_yview[0]+160, "max spd " + string(obj_P1.spd),3,3,0); // draw P1 max speed
    draw_text_transformed(view_xview[0]+512, view_yview[0]+512, "select your ship and move to the starting box " ,3,3,0);
    
     
    }

// P2
if (view_current == 1)
    {  
    draw_text_transformed(view_xview[1], view_yview[1], "HP " + string(obj_P2.HP),4,4,0); // draw P2 HP
    draw_text_transformed(view_xview[1], view_yview[1]+64, "FIRE " + string(obj_P2.countdown),3,3,0); // draw P2 ready to fire
    draw_text_transformed(view_xview[1], view_yview[1]+96, "turn " + string(obj_P2.turn_spd),3,3,0); // draw P2 turn speed
    draw_text_transformed(view_xview[1], view_yview[1]+128, "thrust " + string(obj_P2.thrust),3,3,0); // draw P2 thrust
    draw_text_transformed(view_xview[1], view_yview[1]+160, "max spd " + string(obj_P2.spd),3,3,0); // draw P2 max speed
    draw_text_transformed(view_xview[1]+512, view_yview[1]+512, "select your ship and move to the starting box " ,3,3,0);
    
    }
}



// play room
if (room == rm_play)
{
    //P1
if (view_current == 0)
    {
    draw_text_transformed(view_xview[0], view_yview[0], "HP " + string(obj_P1.HP),4,4,0); // draw P1 HP
    draw_text_transformed(view_xview[0]+320, view_yview[0], "KILLS: " + string(obj_P1.kill_count),4,4,0); // draw score

    }
    
    
    // P2
    if (view_current == 1)
    {  
    draw_text_transformed(view_xview[1], view_yview[1], "HP " + string(obj_P2.HP),4,4,0); // draw P2 HP
    draw_text_transformed(view_xview[1]+320, view_yview[1], "KILLS: " + string(obj_P2.kill_count),4,4,0); // draw score

    }
}
 

Yal

šŸ§ *penguin noises*
GMC Elder
The Draw GUI event means you draw relative to the screen, not relative to the room. So 0,0 is always the top-left corner, no matter how the view moves.
 
Top