# Screen Resolution

## Recommended Posts

How to make images , lines , rectangles fit all screen resolutions?

this work with images and restangles

Yes, with everything.

Of course, it's very simple math - you're using relative values instead of absolute. Relative values range from 0 to 1 and are floating point values, rather than integers like the absolute values are.

For example, using absolute values you'd do it like this;

```dxDrawRectangle(860, 440, 200, 200) -- Creates a Rectangle 200x200 pixels wide, centered for 1920x1080.
```

This will only work for 1920x1080, if you use a smaller resolution it will look as if it's too big. If you use a bigger resolution, it would be too small. To make it relative, you divide the absolute value with the source resolution(In this case it was designed on a 1920x1080 resolution). Then you multiply this by the current screen resolution.

```local screenWidth, screenHeight = guiGetScreenSize()
dxDrawRectangle((860/1920)*screenWidth, (440/1080)*screenHeight, (200/1920)*screenWidth, (200/1080)*screenHeight) -- Creates a Rectangle 200x200 pixels wide, centered for all resolutions.
-- 860/1920 = 0.4479166666666667
-- 0.4479166666666667 * 1920 = 860
```

## Create an account

Register a new account