Is there any way to access a Decal
's Texture
's image size in pixels?
If not, is there any other way, to automatically center an ImageLabel
in a Frame
, without stretching it or messing up it's aspect ratio?
Also, the 9-tile slicing that is enabled when changing ScaleType
to Slice
also has a stretching effect. I cannot make use of that either.
These images are not supposed to be stretched in any way, there are a lot of them, and they all have different sizes.
GuiObjects
have a UDim2
value called Offset
, for both axes. This sizes the object based on pixels, unlike the Scale
value.
As well as that, you can position any object in the exact center (as long as size/2 returns a whole number).
local gui = script.Parent local image = gui:WaitForChild("Image") image.Size = UDim2.new(0,100,0,100) -- the second value for each axis is the Offset, 100 being pixels image.Position = UDim2.new(0.5,-50,0.5,-50) -- this utilizes both scale and offset
Here are the formulas:
Center an object sized with offset
local size = obj.Size local offsetX = size.X.Offset/2 local offsetY = size.Y.Offset/2 obj.Position = UDim2.new(0.5,-offsetX,0.5,-offsetY)
Center an object sized with scale
local size = obj.Size local offsetX = size.X.Scale/2 local offsetY = size.Y.Scale/2 obj.Position = UDim2.new(0.5-offsetX,0,0.5-offsetX,0)
Hope I helped!
~TDP
Q1: Is there any way to access a Decal
's Texture
's image size in pixels?
A1: I'm not sure if there's exactly a way to do that (or one that I know of).
Q2: If not, is there any other way, to automatically center an ImageLabel
in a Frame
, without stretching it or messing up it's aspect ratio?
A2: Yes. This is actually very simple:
local frame = script.Parent -- Or wherever it is local imageLabel = frame:WaitForChild("ImageLabel") -- Or whatever it's called local size = imageLabel.Size imageLabel.Position = UDim2.new(0.5, -size.X/2, 0.5, -size.Y/2)
Hope this helps! If it does, don't forget to click Accept Answer and +1 my Rep!