Jump to content

Relative Shortcut


ShayF2

Recommended Posts

Posted

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.

  • Like 1
Posted (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 by MadnessReloaded
  • Like 1

tJ5zeFm.gif

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

Posted
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.

Posted
local sw,sh = 1360,780

Based off the user's screen and this

tJ5zeFm.gif

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...