1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GUI(healthbar) not scaling with zoom (GameMaker 8)

Discussion in 'Programming' started by Laservision, Mar 28, 2019.

  1. Laservision

    Laservision Member

    Joined:
    Mar 28, 2019
    Posts:
    1
    Hello,

    I'm using a fairly older version of Game Maker which does not have the GUI draw event included, or any GUI codes by that means.

    My "GUI" in this case is just a drawn healthbar. My problem is that it's scaling down when there's a zoom-out.

    Basically, I have two characters in a room that's 4800*2700. My view is
    X: 1440, Y: 540, W: 1920, H:1080 (so it takes the centre of the room), and my port is just 1920*1080.

    I've made another object, called Obj_Camera, with only a step event with the following code:
    Code:
    view_dual(Obj_Char_1, Obj_Char_2, 360)
    
    This code refers to a script (view_dual) with 3 arguments. arg 1 & 2 being the characters and 3th being the padding.

    This is what that script says:

    Code:
    /// view_dual(object1, object2, padding)
    var o1, o2, x1, x2, y1, y2, vw, vh, vb, vscale;
    o1 = argument0; x1 = o1.x; y1 = o1.y
    o2 = argument1; x2 = o2.x; y2 = o2.y
    vb = argument2; vw = view_wport; vh = view_hport;
    vscale = max(1, abs(x2 - x1) / (vw - vb * 2), abs(y2 - y1) / (vh - vb * 2))
    view_wview = vscale * vw
    view_hview = vscale * vh
    view_xview = (x1 + x2 - view_wview) / 2
    view_yview = (y1 + y2 - view_hview) / 2  -300
    This code expands the view when the characters move too far away from each other, so they're both in frame all the time. Kinda like Super Smash Bros (large maps; zoom-out, small map; zoom-in)

    This all works. And here's where the problem occurs.

    This is what I have for the healthbar in the draw event of obj_controller:

    Code:
    draw_healthbar(view_xview+176,view_yview+48,view_xview+752,view_yview+80,(global.GreenHP*100)/1000,c_black,c_red,c_lime , direction,true,true)
    When the game starts up, the health bar is exactly in place. When I move around a bit it still is. But the moment I move away too far from the other character, the screen zooms out and the healthbar scales down.

    I've tried replacing the view_xview with view_xport, view_wport, view_wview but all of those don't work, I've tried creating a variable in the step event of my controller that gets the current display and window;
    Code:
    display_get_width()
    window_get_width()
    and neither of those are working. Maybe that's not the way to do it or maybe I'm doing it wrong, forgot something or just thinking too hard. Whatever I'm trying is not helping and I've been stuck at this process for a few hours now.

    Does anyone know how to solve this, or suggest an alternative? Thanks.
     
  2. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,434
    As you are using an unsupported, decade-old version of software, your only option is to mess with d3d_set_projection_ortho to force different view size/position.
     
  3. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,122
    Store the default dimensions of the view when it will be drawn at 1:1. Then divide the current view dimensions by the default dimensions. Multiply that by your healthbar's values.
     

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