RoundedBox not showing on low resolutions help?

Hi, bassically i am using a rounded box and drawText to display a message to users in the middle of the top of the screen. Some users with low resolutions can’t see it could somebody please fix this for me please and explain why it wasn’t working? Thanks in advance.


 draw.RoundedBox( 6, ScrW() / 2 - 220, ScrH () - 1250 - 10, 440, 205, Color(40, 40, 40, 150))
    draw.DrawText( "Welcome to Sample Gaming! | Have fun! :D", "Trebuchet24", ScrW() / 2 - 215 , ScrH () - 1080, Color(255,255,255,255)) 

It is because you are subtracting fixed values from their screen size which won’t work unless their resolution is at least 1080P - smaller resolutions will have the text off screen.

Do this:


local x, y, w, h, r, n

surface.SetFont( "Your font here" )

r, n = surface.GetTextSize( "Your message here" )

w = ScrW( )
h = n + 4

x = w / 2 - r / 2 - 4

draw.RoundedBox( 6, x, 0, r / 2 + 8, h, your color here )
draw.DrawText( "Your text here", "Your font here", x + 2, 2, color_white )

That would center the text at the top of the screen and account for any resolution.

Thanks alot! :slight_smile:

Would you be able to help me out again please?


 draw.RoundedBox(0, ScrW() - 1912, ScrH() - 40, 300, 15, Color(30, 30, 30, 255))
	if PlayerHealth != 0 then
	draw.RoundedBox(0, ScrW() - 1912, ScrH() - 40, (900) * PlayerHealth / 300, 15, Color(255, 0, 0, 255))
	end


I’ve used this to make a health bar and it works perfect on 1080p but on anything lower it doesn’t work. Please would you help me out? Thanks in advance.

You’re doing the same thing again - don’t subtract exact values from ScrW or ScrH. Figure out the actual size of the element based on a proportion of the screen size and position it accordingly.

[lua]ScrW() - 1912[/lua]
If the player’s screen size is < 1912 that’s going to get drawn off screen. If you want to center do:
[lua]( ScrW() / 2 ) - 150 – Half the screen width - half of the box size[/lua]

So for it to work on multiple resolutions i have to use ( ScrW() / 2 ) to get it into the center of all resolutions and re-position it from there?

[editline]11th October 2014[/editline]

Thanks for this, It helped me understand how it works a little more. :smiley:

Let’s go back to 2nd grade math here. You do what to get half of a number?

Multiply by x where x >0 and less than 2 as a whole number. Then multiply by 1/1 divided by 2.

I’ve being trying for the past 30 minutes with your method but it doesn’t work. Would you please fix it for me? Thanks in advance.



local x, y, w, h, r, n

    surface.SetFont( "healthf" )

    r, n = surface.GetTextSize( " Health: " )

    w = ScrW( )
    h = n + 4

    x = w / 2 - r / 2 - 4

    draw.RoundedBox( 0, x, (ScrH() / 1.5) + 300, r / 2 + 8, h, Color(255, 0, 0, 255) )
    draw.DrawText( " Health: "..PlayerHealth, "healthf", x + 2, 2, color_white )


To get half of a number you can multiply by 0.5 or divide by 2…

This may help you out… Proper hud creation: https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/proper_hud_creation.lua.html

And, how to hard-code your rounded-box sizes to a specific resolution, then go back and apply a modifier ( multiplier ) to the values controlling size ( and position if needed ). https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/understanding_hardcoding_of_screensizes.lua.html

Another example is using this hook: https://dl.dropboxusercontent.com/u/26074909/tutoring/_hooks/acecool_hook_playerchangedresolution/gm_playerchangedresolution.lua

to update a poly size when the user changes resolution to avoid recalculating the poly table each frame: https://dl.dropboxusercontent.com/u/26074909/tutoring/_hooks/acecool_hook_playerchangedresolution/example_usage.lua ( Other tutorials of mine will have the poly:MakeCircle reference, but it is just an example )