I’m trying to figure out the formula for SliceScale so that an ImageLabel using 9-slice has the same scale for all screen resolutions. In theory, the SliceScale would be dynamically change via localscript based on the user’s resolution.
I only found one other thread talking about it (here) but there were no answers unfortunately.
Unfortunately I don’t believe this would work with what I’m trying to do, since UIAspectRatioConstraint is more-so about the sizes of the ImageLabels themselves, rather than the “scale” of the images that show up on said ImageLabels.
local function calculateSliceScale(screenHeight: number)
local constant = 2700
return screenHeight / constant
end
I calculated 2700 by first setting the SliceScale to what looks good on my screen, and then used
s/x = L
Where s is the height of my screen, in pixels, and L is the SliceScale that looked good on my resolution.
For example, my screen is 1080 pixels in height (retrieved via workspace.CurrentCamera.ViewportSize.Y). Additionally, the best looking SliceScale on the 1080 pixel height screen was 0.4. Plugging these into the equation, you get
1080/x = .4
When rearranging algebraically, you get
x = 2700
This is what I set the constant to, and the returned value of the function is then set to the SliceScale property.
Edit: This function can be implemented in many ways, but here’s how I chose to use it
-- Local Script
local ui = Path.to.object
ui.SliceScale = calculateSliceScale(workspace.CurrentCamera.ViewportSize.Y)