abstract
| - In this lesson, I’ll be explaining the first steps to set up a 2D GUI, and some basics about our coordinate system. The first step to creating your GUI is to create a GuiMain and insert it into the player’s PlayerGui object. ———————————————————————– ———————————————————————– A GuiMain object is an invisible overlay that fills the entire screen. If you add Frames or Labels and Buttons to it, they will be drawn. But they have to be put into a GuiMain object. So now that we’ve created out GuiMain object, we can start adding Frames to it. A Frame is a container object, with a BackgroundColor and BorderColor, that can hold other objects (other Frames, in addition to Buttons and Labels). It also will fire events when the mouse either enters and leaves, allowing you to script all kinds of cool stuff. Lastly, it contains a Visible property which can be set to false if you want it (and all of its children) to stop rendering. This is useful if you want to hide a Frame temporarily. ———————————————————————– ———————————————————————– Hold up. What are all these UDim2 objects? Well, they are new. UDim stands for Universal Dimension, and is a compact way to specify both relative and absolute positioning at the same time. When laying out a GUI, it is often necessary to have some positions/sizes change when a parent container’s size changes. Other times, you might want to have a fixed offset that is a specific number of pixels. A UDim lets you do both at the same time. A UDim object consists of a Scale and an Offset. Scale is specified as a number between 0.0 and 1.0 that represents the percentage of your parent’s size. Offset is specified as an integer number, either positive or negative. The final result is the combination of the two: Scale * Parent’s Size + Offset. With the combination of these two values, almost anything is possible. A UDim2 is just two UDim objects, referenced by X and Y. Here is the exact definition of the UDim2.new function: UDim2.new(xScale, xOffset, yScale, yOffset) Now I’ll run through a few examples of using UDim2’s to make Gui objects stick to various parts of the screen. Remember, Position is defined as the top left corner of the Frame. ———————————————————————– One last tip: If you’d like to try playing around with Positions and Sizes, open up a level in edit mode and drop a GuiMain (and some Frames) into the StarterGui. Start playing with the numbers to get a feel for how it changes, and try resizing Roblox to see how using Scales changes your GUI. Note that StarterGui has a ShowDevelopmentGui flag that you can use to hide it while you are working on your level. Make sure its checked or nothing will show up. If you’d like to discuss this blog post, please visit . Next time: Buttons. –Madrak
|