• Best ways of using Scrw and Scrh
    4 replies, posted
Ive had some problems with sizing vgui elements, i've tried using scrh and w so it apparently changes its size correctly to the screen resolution and its not working for me [code] local LuckFrame = vgui.Create("DFrame") local x = 1366 local y = 768 local ScreenW = ScrW( ) / x local ScreenH = ScrH( ) / y LuckFrame:SetPos(300* ScreenW, 300* ScreenH) LuckFrame:SetSize(300* ScreenW, 200* ScreenH) LuckFrame:Center() LuckFrame:SetTitle(config.menuName) LuckFrame.Paint = function() draw.RoundedBox( 2, 0, 0, LuckFrame:GetWide(), LuckFrame:GetTall(), Color( 31,31,32 ) ) draw.RoundedBox( 2, 0, 190* ScreenH, LuckFrame:GetWide(), LuckFrame:GetTall(), Color( 27,27,28 ) ) end LuckFrame:MakePopup() [/code] Im not really a fan of that method neither and wondering is there a better way of doing it?
Why do you set the position, if you Center it afterwards anyway? Yep, there are better ways. For example you could ScrW() * [0-1] to get the same positions on every screen size.
Heres the git to what i was making: [url]https://github.com/3ntity/FreeProjects/tree/master/pointLuck[/url] If i change resolution the sizes are messed up etc. Would using Scrw() - amount and ScrH() - amount work for sizing and positioning?
Here's how I did my Map Vote sizing, I probably should've send you these code snippets earlier :/ Basically I made everything lined up on my resolution using constants (100, 700) and then later started changing the sizes to work on different resolutions. [code] Frame:SetSize(ScrW()-150,ScrH()-150) Frame:SetPos(75,75) ExitButton:SetSize( Frame:GetWide()/29.5, Frame:GetTall()/37.2 ) ExitButton:SetPos( Frame:GetWide() - ExitButton:GetWide() - 10, 10 ) MapArea:SetPos(Frame:GetWide() / 36, Frame:GetTall() / 3.9) MapArea:SetSize(Frame:GetWide()/ 1.06, Frame:GetTall()/ 1.45) [/code]
A tip i got from someone from the site. This is the way of making it work cross resolution on 16:9 if im not mistaken. [CODE] local xScreenRes = 1920 local yScreenRes = 1080 local wMod = ScrW() / xScreenRes local hMod = ScrH() / yScreenRes [/CODE] Then you can use the wMod and hMod as variables but multiplying them example: [CODE] DermaPanel:SetPos(wMod * 500, hMod * 280) DermaPanel:SetSize(wMod * 600, hMod * 500) [/CODE]
Sorry, you need to Log In to post a reply to this thread.