Jump to content

GUI that is arranged to look the same on every resolution.


tommymaster

Recommended Posts

Hi! If i want to make a let's say a rectangle, and i want to put it to my up-right corner that would not show up for the players, who have a resolution of 1366x768. The average screen resolution in my country is 1366x768, but i am not really sure that players won't have a bigger resolution, anyone i asked had a resolution which is smaller than mine. (1920x1080) So if i would put a rectangle to (1700, 1000) it would not even show up on 1366x768. I know that there is a trick, when i divide the pixel cound than multiply it by the player's pixel count it would show up on the right spot (its like 1700/my x pixel count*players x pixel count), but i have to write this everywhere in my scripts, and whenever i make a mistake in maths it makes me puzzle up to half an hour to look for that mistake, for example if i put numbers between () at the wrong spot and stuff like these. So basicly what i want to ask, is there an easier way to arrange the items to the same-like positions on other people's screen with proportional size and height & width? Sorry that i wrote a lot here, please ask if you have any question in connection with this.

Link to comment

I usually use that trick: (In my case, my resolution is 1920 x 1080, so if you have any other resolution just change the values instead of yours.) 

local sX, sY = guiGetScreenSize()

function drawRectangle()

dxDrawRectangle((1770/1920)*sX, (25/1080)*sY, (100/1920)*sX, (50/1080)*sY, tocolor(0, 0, 0, 200), false)

end

addEventHandler("onClientRender", root, drawRectangle)


But you said if there was a method that made it easier, only comes to my mind to do something like this:

local sx, sy = guiGetScreenSize()
local px, py = 1920, 1080
local x, y =  (sx/px), (sy/py)

function drawRectangle()

dxDrawRectangle(x*285, y*143, x*800, y*350, tocolor(0, 0, 0, 220), true)

end

addEventHandler("onClientRender", root, drawRectangle)

In px and py you just have to put your resolution and just draw any element as is shown up. Hope I helped you!

Edited by AlvarO
  • Thanks 1
Link to comment
local sx,sy = guiGetScreenSize()
local sw,sh = 1360,780-- if u change the values in the relative() funcs, be sure to set this to your res and change the other ones as well.

function relative(x,y,w,h) -- this allows for perfect relative values, mta only sizes them to your res so it would be funky for other resolutions.
    x = x/sx*sw
    y = y/sy*sh
    w = w/sx*sw
    h = h/sy*sh
    return x,y,w,h
end

-- then input absolute values into the relative function like so
local x,y,w,h = relative(300,400,100,200)-- whatever u want, x,y,w,h, will be relative values for every res, just be sure to change the res above to your res.

 

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