Jump to content

Relative dx method


Noki

Recommended Posts

Hello,

I've been using the 'standard' method to make relative dx (see example 1), and I notice when I change my resolution or aspect ratio, it looks somewhat abnormal or weird. I was wondering if there is any better methods of creating relative dx.

Example 1:

local sX, sY = guiGetScreenSize() 
  
addEventHandler( "onClientRender", root, 
       function () 
                   dxDrawText( "Hello world", sX * 0.9, sY * 0.9 ) 
       end 
) 

Note: I'm on my phone and I couldn't get a figure going so I wrote 0.9 to substitute for an actual decimal value that would be used. So, just ignore the actual number as it has no significance by itself.

Thank you in advance.

Link to comment

The method I use is this:

local sX, sY = guiGetScreenSize ( ) 
local nX, nY = 1366, 768 -- My screen resolution when I created it 
local x, y = 50, 50 
  
addEventHandler ( "onClientRender", root, 
       function ( ) 
            dxDrawText ( "Hello world", ( x / nX ) * sX, ( y / nY ) * sY ) 
       end 
) 

Link to comment

You can use my tutorial for an example on how to make the process(convert absolute to relative) much faster. Since onClientRender is triggered several times a second, getting rid of any calculations within it is recommended.

Multiplying it once will be more efficient than dividing it first and then multiplying it - since you'll be doing this 30-60 times a second.

Link to comment
You can use my tutorial for an example on how to make the process(convert absolute to relative) much faster. Since onClientRender is triggered several times a second, getting rid of any calculations within it is recommended.

Multiplying it once will be more efficient than dividing it first and then multiplying it - since you'll be doing this 30-60 times a second.

But your thing just calls a function several times a second. It doesn't eliminate the constant mathematical calculation that occurs.

Link to comment
But your thing just calls a function several times a second. It doesn't eliminate the constant mathematical calculation that occurs.

You read the wrong part of the tutorial. I meant this part;

Edit:

I'll also go ahead and quote a reply I made a while ago, where I explained how I (somewhat automatically?) convert my DX stuff to relative. Remember to edit it to so it uses the same screen size variables as you do! (screenX + screenY)

I use a website where you can run Lua code to make the process very fast and straight forward, since doing it all manually is a very tedious process. Especially with DX functions.

Simply paste this code(into the website linked above) and enter the appropriate values. Then copy the output and you're golden.

local sX, sY, wX, hY = 480, 240, 969, 570; -- Paste the absolute values here 
local sourceWidth = 1920;    -- Change those to the source values. 
local sourceHeight = 1080;   -- Change those to the source values. 
local nSX, nSY, nWX, nHY = (sX/sourceWidth), (sY/sourceHeight), (wX/sourceWidth), (hY/sourceHeight); 
  
for i=0, 47 do 
   print(""); -- This is just to clear the print window, so you don't confused what to copy. 
end 
  
print(tostring(nSX).."*screenX, "..tostring(nSY).."*screenY, "..tostring(nWX).."*screenX, "..tostring(nHY).."*screenY"); 

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