To calculate some GUI position (0 to 1), I’ve seen a lot of examples telling to use the mouse.ViewSizeX and mouse.ViewSizeY to indicate the current screen dimensions.
However mouse.ViewSizeY shows a wrong screen dimension!
Here an example:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local camera = workspace.CurrentCamera
local mouseScreenSize = Vector2.new(mouse.ViewSizeX, mouse.ViewSizeY)
local cameraScreenSise = camera.ViewportSize
print("mouseScreenSize: ", mouseScreenSize)
print("cameraScreenSize: ", cameraScreenSise)
mouseScreenSize: 1646, 596
cameraScreenSize: 1646, 668 -- << THE CORRECT Y SCREEN DIMENSION
Is this a Roblux Lua bug?
Pretty sure this is because of the top bar. Mouse.ViewSize most likely is cut off by the top bar, while camera.ViewportSize is not.
“This property [ViewportSize] ignores the GUI inset applied by the top bar…”
EDIT: After further reading, it seems like Mouse.ViewSizeY includes the space occupied by the top bar too, so I’m not sure.
Thanks for your reply.
In https://developer.roblox.com/en-us/api-reference/property/Mouse/ViewSizeY it says This length includes the space used by the topbar..
How it INCLUDES if the
mouse.ViewSizeY < camera.ViewportSize.Y ?
And what’s the practical usage of
Back in ye olde days Camera didn’t have a ViewportSize
However mouse did have ViewSizeX/ViewSizeY
I imagine it’s a matter of backwards compatibility without any deprecation, rather than having a practical usage.
However at https://web.archive.org/web/20120710235413/http://wiki.roblox.com/index.php/ViewSizeY_(Property) it says Size of the viewport’s Y in pixels. This is the height of the game window. which is not true…
So, is there any real application for
mouse.ViewSizeY, once it doesn’t give the correct height of the game window?
We didn’t have a TopBar back then. Most of the UI was at the bottom of the screen instead.
ETA: When the top bar was introduced at first, unless you used offset and didn’t mind your content being covered by a semi-transparent black bar - you couldn’t show anything at the top of the screen, everything was simply pushed down 36 px when it came out.
So we can deduce that
mouse.ViewSize is USELESS and has to be informed as a BUG?
Personally, I don’t think it’s worth it given we have an alternate method which works. It’s not useless as older and updated games will still use it.
72 is the difference in the Y heights, 72/2 = 36 which is the inset of the top bar. One is inclined to deduct it is perhaps purposely like that so older games still have the central mouse focus in the right point. Personally, I’d be more inclined to just ask for better documentation of it’s behaviour rather than as a bug.
Where can I suggest to Roblox a better documentation based on this case?