Why does UIScale affect AbsoluteSize/Position like this?

I have this info that appears hwen you click on a button. The Backpack has a UIScale in it.

function BackpackUIController:SetInfoPosition()
	task.wait() -- Wait a split second in case of touch

	local MouseLocation = UserInputService:GetMouseLocation()

	local Offset = HUD.Backpack.Info.Triangle.AbsoluteSize.X / 2

	HUD.Backpack.Info.Position = UDim2.fromOffset(
		(MouseLocation.X + Offset) - HUD.Backpack.AbsolutePosition.X,
		(MouseLocation.Y + Offset - Constants.TOP_BAR_OFFSET) - HUD.Backpack.AbsolutePosition.Y
	)

	print("Mouse", MouseLocation, "Info", HUD.Backpack.Info.Position)
end

When the scale is set to 1, the info appears in the correct spot, basically my mouse being the corner of the info frame.
image
However, if I set the UIScale to 1.4, and click on the frame, it not sets the info frame way off to the side.
image

I am unsure why this is happening. I am using AbsoluteSize/Position of the frame to get positions correctly, but it’s always skewed. If I increase the scale, it just gets further and further away from the mouse.

For anyone asking, the UIScale for all my frames gets changed to 1.4 if the player is a smaller device (mobile) that way all the frames are upscaled without needing to do crazy work to scale each frame specifically.

Idk if I need to times the position by the scale or something.

I would use two separate UIScale instances in this case. One for the backpack, one for the info container. I’m assuming you use the same one for both.

Divide the position by the scale should work. Or some combination of dividing a calculated position by the scale.

HUD.Backpack.Info.Position = UDim2.fromOffset(
	((MouseLocation.X + Offset) - HUD.Backpack.AbsolutePosition.X) / UISCALE.Scale,
	((MouseLocation.Y + Offset - Constants.TOP_BAR_OFFSET) - HUD.Backpack.AbsolutePosition.Y) / UISCALE.Scale
)
3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.