Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to get physical size of the display/window? (not resolution)

Asked by 7 years ago
Edited 7 years ago

Is there any way to get the size of a users' screen in a unit such as millimetres, centimetres, inches, etc.? I am trying to create GUIs that will display on the screen as a specific size.

Example: I want a display to be 10x12 cm on all displays, regardless of the size or resolution of the display.

Edit below:

Take two example displays with an X resolution of 1920: Display1 Width: 10 inches Display2 Width: 20 inches

Pixel density (PPI) of the displays (resolution/size): Display1: 192px/in Display2: 96px/in

A frame on both displays with a width scale of 0.5 (1920/2PPI or WidthInInchesscale) Display1 Frame Width: 5in Display2 Frame Width: 10in

5 ~= 10

This is the problem I want to solve. I do not want the GUI to scale to the display. I also do not want to base it off of pixels because of variation in pixel density.

Using the previous example displays, a frame with a width of 500px: Display1 Frame Width: 2.6in (approximation) Display2 Frame Width: 5.2in (approximation)

1
No point, Roblox done the work for you, e.g (0.5,0,0.5,0) abnotaddable 920 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

Using the default sizing and positioning type of UDim2, you can scale the gui so that it is in the right location. Each screen is a different size, but roblox has already done the work for you. All you have to understand is that 0 is 0 and 1 is the other end of the screen for both the width(X) and height(y).

UDim2.new(number xScale, int xOffset, number yScale, int yOffset)

tb = Instance.new("Textbox")
tb.Parent = game.StarterGui
tb.Position = UDim2.new(0.5, 0, .5, 0) -- Will put top left corner of textbox in the middle of the screen

If you wish to get the exact size in pixels...

You will need to get the mouse from the local player(I'm using a local script in this example)

local mouse = game.Players.LocalPlayer:GetMouse()

Then, you can obtain the the width using mouse.ViewSizeX and the height of the screen using mouse.ViewSizeY

while true do
    wait(.1)
    print(mouse.ViewSizeX .. ", " .. mouse.ViewSizeY)
end

I added in a loop so you can test this in studio by resizing the side bars while in play solo

(Whole Script)

mouse = game.Players.LocalPlayer:GetMouse()

while true do
    wait(.1)
    print(mouse.ViewSizeX .. ", " .. mouse.ViewSizeY)
end

Credits to Legojoker's reply here(give him an upvote if this helps!): https://scriptinghelpers.org/questions/23265/how-big-is-the-roblox-screen

*Always try look up other scripting helper questions before posting your own in case its already been answered

Hope this helps. Let me know if this still isn't what you were exactly looking for.

0
When I say size I am referring to a measurement of physical size. A width of 0.5 (scale) on a small screen will be smaller than a 0.5 (scale) on a larger screen; I do not want it to scale to the display. Additionally, I do not want to base it off of pixels as different displays have different pixel densities. Epidemiology 116 — 7y
0
As far as I know there is no way to do this, not even in modern programs. In fact, it's possible Windows doesn't even know you have, say, a 24" monitor. unmiss 337 — 7y
0
It is completely possible, the display itself provides the size. https://en.wikipedia.org/wiki/Extended_Display_Identification_Data Epidemiology 116 — 7y
0
Oh ok, then I'm not sure. I'll look into it more. dragonkeeper467 453 — 7y
0
Updated post, please see added section dragonkeeper467 453 — 7y
Ad

Answer this question