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 Proud owner and developer of ZNEXT: Aftermath. Enter a post-apocalyptic San Andreas and fight over 30 types of enemies and bosses with varying difficulties and skills, improve and customize your character by leveling up, completing challenges and a solid lootbox system with no Pay-to-Win mechanics that will break your experience. Meet new characters, creatures and weapon metas, experience an innovative combo-based melee system, or join our solid PvP modes to show other survivors who’s boss. Español, Pусский, Türk, عربى, Polski, Português IP: mtasa://104.36.110.227:22003 - Discord: https://discord.gg/CxMxjvC5pB
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 Proud owner and developer of ZNEXT: Aftermath. Enter a post-apocalyptic San Andreas and fight over 30 types of enemies and bosses with varying difficulties and skills, improve and customize your character by leveling up, completing challenges and a solid lootbox system with no Pay-to-Win mechanics that will break your experience. Meet new characters, creatures and weapon metas, experience an innovative combo-based melee system, or join our solid PvP modes to show other survivors who’s boss. Español, Pусский, Türk, عربى, Polski, Português IP: mtasa://104.36.110.227:22003 - Discord: https://discord.gg/CxMxjvC5pB
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