SliceScale formula

(FYI this is SliceScale for those who aren’t familiar.)

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.

Anyone know how I can calculate it?

1 Like

Try using an UIAspectRatioConstraint | Roblox Creator Documentation

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.

Bump! Currently dealing with this same problem. Any solutions?

Alright. It appears I fixed my issue.

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)
6 Likes

Thanks for your code, it’s currently 0:45AM and I’ve been looking for a solution for this problem for a really long time.

I’ve tried everything, changing size of the image and such but your solution worked perfectly.

Thanks for saving my sleep :pray:

1 Like

Hey! Its been a while, but how would I calculate both Y and X at the same time to get a good cornersize?

did you figure it out? i would need this aswell

I still haven’t found a way to do this :disappointed:

1 Like