# How to find out screen coordinates?

## 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: 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

By using math,

screenX / 2 is the horizontal middle

screenY / 2 is the vertical middle

this gives the center.

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

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

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

## Create an account

Register a new account