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




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:
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:

/// 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:

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;
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.


ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
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.


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.