Windows [SOLVED] New way to make HUD follow the screen?

Discussion in 'GameMaker Studio 2 Community Tech Support' started by mont266, Jan 11, 2019.

  1. mont266

    mont266 Member

    Joined:
    Jan 10, 2019
    Posts:
    6
    Hi!

    In GMS1.4 I always drew my HUD using this code:
    Code:
    draw_healthbar(view_xview[0]+32,view_yview[0]+32,view_xview[0]+256,view_yview[0]+50,global.playerhealth,c_black,c_red,c_green,0,false,true);
    
    But I am aware that this no longer works for making my healthbar follow the view.

    I have tried:
    Code:
    view_camera
    and
    Code:
    view_xport
    but still can't get the HUD to move with the camera. Can anyone help me with a new way to tackle this?

    Cheers!
     
  2. Tsa05

    Tsa05 Member

    Joined:
    Jun 21, 2016
    Posts:
    477
    Code:
    var cam = view_camera[view_current];
    
    var vx = camera_get_view_x(cam);
    var vy = camera_get_view_y(cam);
    var vw = camera_get_view_width(cam);
    var vh = camera_get_view_height(cam);
     
  3. mont266

    mont266 Member

    Joined:
    Jan 10, 2019
    Posts:
    6
    Thanks! I tried messing about with the values and I sorted it, but im stuck with another problem, it technically 'follows' the camera but it stretches the bar out along with the camera? Am I doing something wrong?

    My code is here:
    Code:
    draw_healthbar(vx+32,vy+32,vw-1664,vh-1030,global.playerhealth,c_black,c_red,c_green,0,false,true);
    
     
  4. Tsa05

    Tsa05 Member

    Joined:
    Jun 21, 2016
    Posts:
    477
    Ah, I don't think you need vw and vh in this case. Those are just the width and height of your view.
    Looks like you wanted to go from the corner+32 to the corner +256

    draw_healthbar(vx+32,vy+32,vx+256,vy+50,global.playerhealth,c_black,c_red,c_green,0,false,true);
     
    mont266 likes this.
  5. mont266

    mont266 Member

    Joined:
    Jan 10, 2019
    Posts:
    6
    Thank you so much! It's taking me a little time to adapt to GMS2 from GMS1.4, but im getting there. If I could hug you I would! Thanks a lot!
     
    Tsa05 likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice