How to optimize my hud for all screens?
Cause some of my players see texts and others see only half of it.
Some people even dont see text at all.
HELP!
https://files.facepunch.com/forum/upload/149560/8cc55ca1-662d-4564-b43a-734f974d4497/image.png
https://files.facepunch.com/forum/upload/149560/cdb38b08-1b94-434f-b8d4-cb396cb34948/unknown.png
ScrW
ScrH
+
simple Math
I used scrw + scrh
instead of ScrW()-1897 you could just do a few pixel plus, without ScrW...
Istead taking an unique value from the screen globals, take a value form the global itself, i do like that and aways works.
exemple:
function DrawHUD()
local ScreenWidth = ScrW()
local ScreenHeight = ScrH()
draw.SimpleText("Health", "Font3", (ScreenWidth/2.15 * 2),(ScreenHeight/1.214), Color(230,230,230,255))
end
Divide each one until you find the place you like then you can see that is the same in other resolutions.
draw.SimpleText("Health", "Font3", +27, ScrH()-108, Color(230,230,230,255))
Like this?
yep. that probably wont fix your fail, but it reduces performance because gmod dont have to calculate screen resolution minus the number..it just have to put the element at that pixel
I usually do a percent of the screen, like this:
draw.RoundedBox(0, ScrW() * 0.8, ScrH() * 0.8, w, h, Color(255, 0, 0, 255))
The box is taking up 80% of the screen on each axis.
All wrong.
No reason to ScrW() * or / or + when you literally want it 100 pixels off the screen. Just do 100 as x and do ScrH() - (25 * (howManyBarsUhave - 1)) as y.
That is a very unhelpful blanket statement. In reality, the "right" way to do it depends on how you want your HUD to behave. If you want consistent scaling on all resolutions, go with percentages, as Livaco stated.
If you only care about aligning to the edges of the screen, then you need to consider when it is and isn't appropriate to use ScrW and ScrH. If your element is aligned to the top or left sides, then you shouldn't use them. If your element is aligned to the right or bottom, then you should. Just remember that the top left of the screen is 0, 0 and the bottom right is ScrW, ScrH, and you shouldn't have any problems with this.
Keep in mind, if you want to properly offset it based off ScrH(), you need to minus the actual height of the box/text on top of the original subraction for spacing between it and the edge of the screen if you want to go the subtraction method. The problem you are having is you are(in the OP) subtracting a static hard-coded value for the y axis, which as you've probably realized, won't work for all displays(captain obvious i know). For getting the height of the text, you could probably find the font size of the font your using from the wiki and use that.
If you want the HUD to also scale correctly depending on the resolution instead of getting smaller, you'll need to use a division/multiplication method for sizing(not for position, though), which is kinda off topic from the op, but just incase.
I would not have said what I said if I knew for a fact he was doing something else, I even mentioned that since he "literally wants it 100 pixels off the screen" that there is no need to add, divide or multiply anything. He can simply just set it to 100 and it'll function for all resolutions.
However the y position requires a bit of SICK MATHS, simply take the screen height and subtract whatever number you want.
Declaring everything posted before as "all wrong" is what I take issue with. I guess you missed the part where Trackster suggested literally the exact same thing you did. And for all you know, maybe the OP wants some scaling too, but just doesn't know where to begin with that, and just wants to do the perceived "easier" thing.
More importantly, if all you do is fix their code for them, they will never learn how to do it themselves. You need to explain the why, no matter how simple and trivial it may seem to you, because clearly, there is something they don't understand.
exactly!
Sorry, you need to Log In to post a reply to this thread.