• HUD resolution problem
    18 replies, posted
Hello, I made my first HUD and uploaded it to the Workshop, but I noticed that some people had issues with the resolution and that some roundedboxes or text are out of screen. I made the HUD for 1920 x 1080 resolution, but how can I change this to all resolutions? For example draw.RoundedBox and draw.SimpleText: draw.SimpleText(clip, "Font1", ScrH() - 155, 940, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER ) draw.RoundedBox( 0, 715, ScrH() - 100, 4.6 * Health, 50, Color( 255,255,255))
what about ScrW()
I was thinking about that aswell, but does this fully solve the problem? Because roundedboxes appear in their screen without ScrW().
ScrW() also gets the player's screen width resolution, so i don't see why it wouldn't solve the problem.
Okay, thank you for your time and help
Inside your text in case position you are setting as reference screen height and not screen width, also seems like in the same function you just placing the text at900px height and not a value from ScrH In your rounded box you are most likely doing the same, except than you are not setting the wide correctly, I recommend you to read functions parameters in order to fix the issue and use ScrW for wide and ScrH for height
Adding the ScrW() did not solve the problem. People have still issues. For me the text is in the good position, but for others it in the middle of there screen. draw.SimpleText(store, "Text5", ScrH() - 110, ScrW() - 973, Color( 255, 255, 255, 100), TEXT_ALIGN_CENTER ) draw.SimpleText(clip, "Text6", ScrH() - 155, ScrW() - 980, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER )
draw.SimpleText(store, "Text5", ScrH() - 110 * scale, ScrW() - 973 * scale Parameters for draw.SimpleText are text, font, x pos, y pos You're doing: text, font, ypos, xpos Since Screens are larger than wider, your text will be out of screen, just a note, if you have to use a costant bigger than 256, you're doing something really wrong in UIs
Thanks for helping me out! Im not very skilled yet when it comes to LUA. Still learning the bits and parts. Since im running 1920 x 1080 I don't know if this would work for everybody: draw.SimpleText(store, "FONT", ScrW() - 950, ScrH() - 133, Color( 255, 255, 255, 100), TEXT_ALIGN_CENTER ) draw.SimpleText(clip, "FONT", ScrW() - 995, ScrH() - 140, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER )
Ideally you use percentages of the screen's width and height, not positioning based on hardcoded values. Unless somebody manages to use your script while on 800x600 resolution, your code right now should work fine for everyone. It's still a bad practice, though. Use multiplication instead. For example, if you wanted your text to be in the center of the screen horizontally, use ScrW() * 0.5. The same concept applies for vertical positioning.
You are still using big constants ScrW returns screen width, if you are under 1920 yeah, 1920 - 950 will be 970, but what about if you are at 1280x720? It will go out of bounds at 300 Remember, if you are using a number bigger than 256, you are doing something wrong
Like this? draw.SimpleText(store, "Text5", ScrW() - 950 * 1, ScrH() - 133 * 1, Color( 255, 255, 255, 100), TEXT_ALIGN_CENTER ) draw.SimpleText(clip, "Text6", ScrW() - 995 * 1, ScrH() - 140 * 1, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER )
If your making a hud on the left side of the screen you may not even need ScrW(), so it may be the ScrH() thats causing the issue. Another note is that you NEVER want to take a screen width and then minus a certain amount of pixels as when the ScrW() changes the position it was in will have moved.
No: Remove 950, 995, 133, and 140 from your code entirely for a moment. Just play purely with ScrW() and ScrH() multiplied by any number between 0 and 1 and you should get what we're trying to tell you.
Something like this should work for every resolution then? draw.SimpleText(store, "Text5", ScrW() * 0.505, ScrH() * 0.8761, Color( 255, 255, 255, 100), TEXT_ALIGN_CENTER ) draw.SimpleText(clip, "Text6", ScrW() * 0.480, ScrH() * 0.870, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER ) draw.RoundedBox( 0, ScrW() - 975 * 1, ScrH() - 130 * 1, 3, 15, Color( 255,255,255, 255 )) 
There's still a 975 in RoundedBox Also about percentages, you have to understand what's the point of it, if you do store being at 0.505...It won't be in the middle of the screen, you're doing after it 0.48 for the clip, it will look good maybe in 1080p, but maybe in 720 text will overlap If you want something being near another element, just do: ScrW() * 0.5 - something But that "something" just be sure it's not THAT big...Like you're doing fixed values, not absolute
But there is no way to get the position I want be doing 0.5, 0.1, 1.2 or something. This is the exact position I want, but why would this not work for every resolution? draw.SimpleText(store, "Text5", ScrW() * 0.505, ScrH() * 0.8761, Color( 255, 255, 255, 100), TEXT_ALIGN_CENTER )
It will be the same position on every resolution when you do it like that, the next issue is whether or not it will overlap anything important.
Sorry, you need to Log In to post a reply to this thread.