UDim2: Difference between revisions
>Mr Doom Bringer No edit summary |
>Mr Doom Bringer No edit summary |
||
Line 11: | Line 11: | ||
'''Scale''' is a number between 0.0 and 1.0 that is a percentage of the parent object's size. For example, if the parent object is 50 pixels wide, a UDim scale of 0.5 would be 25 pixels wide. 0.5 makes the size 50% of it's parent, same as 0.38 is 38%, 0.85 is 85%, and so on. | '''Scale''' is a number between 0.0 and 1.0 that is a percentage of the parent object's size. For example, if the parent object is 50 pixels wide, a UDim scale of 0.5 would be 25 pixels wide. 0.5 makes the size 50% of it's parent, same as 0.38 is 38%, 0.85 is 85%, and so on. | ||
'''Offset''' is a specified [[ | '''Offset''' is a specified [[Integer]]. This is a non changing value that is factored into the UDim calculation. | ||
The final result is a combination of Scale and Offset. '''Scale * Parent's Size + Offset'''. | The final result is a combination of Scale and Offset. '''Scale * Parent's Size + Offset'''. |
Revision as of 23:57, 9 March 2010
A UDim2 is a Data Type that uses 2 coordinates to place objects in the GUI system. UDim stands for Universal Dimension, and uses 2 coordinates.
Makeup
UDim2.new(xScale, xOffset, yScale, yOffset)
A UDim consists of a Scale and an Offset. These are used to figure out where exactly the UDim's position is.
Scale is a number between 0.0 and 1.0 that is a percentage of the parent object's size. For example, if the parent object is 50 pixels wide, a UDim scale of 0.5 would be 25 pixels wide. 0.5 makes the size 50% of it's parent, same as 0.38 is 38%, 0.85 is 85%, and so on.
Offset is a specified Integer. This is a non changing value that is factored into the UDim calculation.
The final result is a combination of Scale and Offset. Scale * Parent's Size + Offset.
A UDim2 is simply two of these mashed together, for an X and Y.
Use
UDim2 values are used only in GUI system objects. This allows you to place objects on the player's screen exactly where you want them to go. Also, because the UDim2 scales according to it's parent's size, you can set up a GUI that will scale to a different screen size.
Here are a few code examples of objects placed using UDim2 locations. Remember that "zero" is the top left corner.
–A 50×50 frame 5 pixels from the top, 10 pixels from the left mainFrame.Position = UDim2.new(0.00, 10, 0.0, 5) mainFrame.Size = UDim2.new(0.0, 50, 0.0, 50) –A frame that is half the size of the main screen, in the center mainFrame.Position = UDim2.new(0.25, 0, 0.25, 0) mainFrame.Size = UDim2.new(0.5, 0, 0.5, 0) –A 50×50 frame in the top right corner mainFrame.Position = UDim2.new(1.0, -50, 0.0, 0) mainFrame.Size = UDim2.new(0, 50, 0, 50) –A frame that is 1/4 the size of the screen, –in the bottom right corner –(For position I took the corner’s position (1.0) – the – size (0.25) to get the position (0.75)) mainFrame.Position = UDim2.new(0.75, 0, 0.75, 0) mainFrame.Size = UDim2.new(0.25, 0, 0.25, 0)