Jump to content

How to find out screen coordinates?


rusztamas

Recommended Posts

Hi!
I want to learn using dxDraws properly, but i don't know where can i check screen coordinates, and i want to draw a straight line, and place a box in the center, and i'm trying my best and it is like this: 

mta_screen_2016_12_06_23_37_41.png

Coding:

local x,y = guiGetScreenSize()

function drawStuff()
	local bg = dxDrawRectangle ( 500, 250, 500, 500, tocolor ( 0, 0, 0, 155 ) )
	local line1 = dxDrawLine ( 600, 500, 300, 250, tocolor(0,0,0,255))
end

addEventHandler("onClientRender", root, drawStuff)
addCommandHandler ("asdasd", drawStuff)

Can you help me? Please?

Link to post

like this : 

local x,y = guiGetScreenSize()

function drawStuff()
local bg = dxDrawRectangle ( x*500, y*250, x*500, y*500, tocolor ( 0, 0, 0, 155 ) )
local line1 = dxDrawLine ( x*600, y*500, x*300, y*250, tocolor(0,0,0,255))
end

addEventHandler("onClientRender", root, drawStuff)
addCommandHandler ("asdasd", drawStuff)

and this for make it show at same position in all res

local x,y = guiGetScreenSize()
local sx, sy = x/1280, y/720 ----- put your res here 
function drawStuff()
local bg = dxDrawRectangle ( sx*500, sy*250, sx*500, sy*500, tocolor ( 0, 0, 0, 155 ) )
local line1 = dxDrawLine ( sx*600, sy*500, sx*300, sy*250, tocolor(0,0,0,255))
end

addEventHandler("onClientRender", root, drawStuff)
addCommandHandler ("asdasd", drawStuff)

 

Link to post

An easy way is to position the dxdraw things using just number values so that it looks as you want it to on your resolution. And after that use this example to convert the number values to floating point ones and multiply by screen width and height. 

 

The dxDrawRectangle you posted will look like this: 

local x, y = guiGetScreenSize()

dxDrawRectangle ( x* 0,2604166667 , y* 0,2314814815 , x* 0,2604166667, y* 0,462962963 , tocolor ( 0, 0, 0, 155 ) )

And it will stay same size and on same position on any screen resolution. 

 

What i did was:

I divided the first number by my pc screen resolution width so 500/1920. The second number i divided by the height so 500/1080.

Then the third number again divided by screen width and forth number-by screen height. 

After this i just multiply each result of each division with the corresponding screen dimension. 

x = screen width

y = screen height

Edited by koragg
Sry for any typos, I'm from phone
Link to post

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