Integer scaling

currently i will have around three pixel perfect ui elements in a menu you might see often, i don’t like mixels, so is there a way to snap to integers where the pixels are perfect squares?

You can get the closest perfect square by taking the square root of the number, rounding it to the nearest whole number, and then squaring it again.

Here is an example:

local Number = 23
local SquareRoot = math.sqrt(Number)
SquareRoot = math.round(SquareRoot) -- 5

local Square = SquareRoot^2 

print(Square) -- 25
2 Likes

we might just have a genius here

1 Like

im just assuming this is the bad guy from the show called mixels

1 Like

ok then, how do i convert scale to offset to actually be able to use this :eyes:

To get the actual size in pixels from a scale, just multiply the scale by the parent’s size. for example:

local Frame = Instance.new('Frame')
Frame.Size = UDim2.fromOffset(200, 200) -- The frame is 200x200 pixels

local TextButton = Instance.new('TextButton')
TextButton.Parent = Frame
TextButton.Size = UDim2.fromScale(0.5, 0.5) 
-- 0.5 means 50% of the parent's size
-- So if the parent is 200x200, this button will be 100x100 pixels.
-- Scale is a fraction of the parent: 
-- 1 = 100%, 0.5 = 50%, 0.25 = 25%, etc.

-- To convert scale to offset, multiply the scale by the parent's size
local buttonWidth = Frame.AbsoluteSize.X * TextButton.Size.X.Scale
local buttonHeight = Frame.AbsoluteSize.Y * TextButton.Size.Y.Scale

-- Offset only works with whole numbers, so it's best to round
buttonWidth = math.round(buttonWidth)
buttonHeight = math.round(buttonHeight)

print(buttonWidth, buttonHeight) -- Prints 100, 100
1 Like

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