ShayF2 Posted January 2, 2018 Posted January 2, 2018 This is a simple function designed to take absolute values, like 400,600,200,150 and such, and turn them into relative values. This is useful when creating gui and dx elements to match them up with every screen. That way different resolutions can resize and reposition accordingly. MTA has its own method of calculating relative values, however it does not reposition, it only resizes. So here you go. Be sure to change 1360,780 to your own resolution. And here is an example of using this: local x,y,w,h = relative(500,500,100,200); dxDrawRectangle(x,y,w,h,tocolor(255,255,255,255)) local sx,sy = guiGetScreenSize() local sw,sh = 1360,780 function relative(x,y,w,h) local x,y,w,h = x/sx*sw,y/sy*sh,w/sx*sw,h/sy*sh return x,y,w,h end I hope this is of some help to you. 1
DRW Posted January 2, 2018 Posted January 2, 2018 (edited) 11 hours ago, ShayF said: This is a simple function designed to take absolute values, like 400,600,200,150 and such, and turn them into relative values. This is useful when creating gui and dx elements to match them up with every screen. That way different resolutions can resize and reposition accordingly. MTA has its own method of calculating relative values, however it does not reposition, it only resizes. So here you go. Be sure to change 1360,780 to your own resolution. And here is an example of using this: local x,y,w,h = relative(500,500,100,200); dxDrawRectangle(x,y,w,h,tocolor(255,255,255,255)) local sx,sy = guiGetScreenSize() local sw,sh = 1360,780 function relative(x,y,w,h) local x,y,w,h = x/sx*sw,y/sy*sh,w/sx*sw,h/sy*sh return x,y,w,h end I hope this is of some help to you. But what if you are using other aspect ratio, like 4:3 or 21:9? Because it looks like you're using a 16:9/16:10 ratio as a reference. PD: It will sure be a relief for a lot of people messing with HUDs. Edited January 2, 2018 by MadnessReloaded 1
ShayF2 Posted January 2, 2018 Author Posted January 2, 2018 10 hours ago, MadnessReloaded said: But what if you are using other aspect ratio, like 4:3 or 21:9? Because it looks like you're using a 16:9/16:10 ratio as a reference. PD: It will sure be a relief for a lot of people messing with HUDs. Aspect ratio wont matter, this math is based off the users screen.
DRW Posted January 2, 2018 Posted January 2, 2018 local sw,sh = 1360,780 Based off the user's screen and this
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now