Jump to content

Relative Shortcut


ShayF2

Recommended Posts

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
Link to comment
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
Link to comment
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.

Link to comment

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