Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Animation keyframes are defined by creating states in categories. If an animation uses two states in the same category then the animation will tween between them
The tutorials contained within this section provide an introduction to working with the Gum UI tool. This tutorial is a great place to start whether you are an artist who will be creating screens and components in Gum, or if you are a programmer who will be integrating Gum into your game or application.
If you are using Gum in a game project, you may want to continue reading other sections after you finish these tutorials.
Components are reusable collections of instances. Components can be added in the project's Components folder. Examples of Components include:
Button
HealthBar
Slider
Menu
Components can be small and reusable, such as a Label, or they can be large complex objects such as a settings menu with dozens of options.
Component instances can be added to other Components or to Screens.
The Blend variable controls how the selected instance combines its colors with whatever is drawn before. The final appearance of a NineSlice depends on its Blend, Alpha, Source File, and Color values.
For more information and examples, see the Sprite Blend page.
Introduction
The Components tutorial shows how Text and ColoredRectangle instances can be sized and positioned according to the Button that they are a part of. Instances can use other instances as their parents. Gum does not place a limit to the depth of the parent/child hierarchy, enabling flexible and responsive layouts through.
Parent/child relationships are useful for
Automatically adjusting margins and backgrounds
Word-wrapping text relative to a parent
Stacking objects on top of each other or side by side
Placing objects next to other objects which are dynamically sized
Creating tables and other complicated layout objects
For this example we'll create a Component for displaying distance. This component has two Text instances:
ValueText - the Text instance responsible for displaying the value for the distance. For example "100".
UnitsDisplay - the Text instance responsible for displaying the units for the distance. For example "km" for kilometers.
The two Text instances will have different colors so that ValueText stands out.
A single Text instance can support inline styling. We use two text instances here to show how to work with the Parent variable, but for more info see the Text property page.
To create our component:
Create a new component named MeasurementDisplay
Drop two Text objects in the newly-created component
Name the first ValueText
Name the second UnitsDisplay
Next we'll make the UnitsDisplay use the ValueText as its parent:
Select the UnitsDisplay Text instance
Change its Parent
to ValueText
Change its X Units
to Pixels From Right
. This makes the text object positioned according to its parent's right edge
Change its X
to 10
. This means the UnitsDisplay text is 10 units offset from the right edge of its parent ValueText
Verify its Y
is 0
The ValueText actual width should be based on its contents, so we'll do the following:
Select ValueText
Change Width Units
to Relative to Children
Change Width
to 0
By setting these values, ValueText is now sized according to its children, which in this case are its letters.
You may have noticed that UnitsDisplay is also a child of the ValueText. However, since UnitsDisplay is explicitly positioned outside of the bounds of its parent ValueText, then ValueText ignores this child when calculating its own Width. For a detailed discussion of Width Units and whether children are ignored, see the Width Units page.
Now that we have adjusted the position, size, and parent values on our Text instances, let's modify the color of the UnitsDisplay:
Select the UnitsDisplay
Change Red
to 200
Change Green
to 150
Change Blue
to 0
Now that we have set up a parent/child relationship between ValueText and UnitsDisplay, UnitsDisplay automatically adjusts its position in response to changes in ValueText. Any change on ValueText resulting in the right-side of the parent changing automatically adjusts the position of UnitsDisplay.
For example, if we change the Text property on ValueText, it grows or shrinks in response.
As mentioned above, changing the Text property causes ValueText to grow or shrink. However, regardless of its size, the Width
property is still set to 0.
The Width
variable is used in combination with its Width Units
to calculate an effective width. In this case, the effective width is determined by the Text property on ValueText. It's important to note that all Gum objects have effective values for x, y, width, and height, all of which are determined by their respective units values.
Children always depend on their parents' effective values rather than their explicitly set values. Gum helps us visualize the effective values when we mouse over one of the resize handles on the selected object. For example, the following image shows the Width
, Width Units
, and effective width values of our ValueText.
The ability to expose variables in Gum makes components flexible. For this example we will continue the Button example from the last tutorial.
The last tutorial created a Button component with Text and ColoredRectangle instances. The instances were set up to be positioned correctly according to the size of the button.
We then created a MainMenu screen and added a few instances of the Button component to the MainMenu screen.
While the size and positioning functionality in our button works well, the Text itself always says "Hello".
By default a Button only exposes its top level variables. Variables on instances inside the button are not available outside of the button. In programming terms these variables are considered protected.
However, we can expose variables on instances so that they can be modified in our MainMenu screen.
To do this:
Select TextInstance under Button
Find the Text
variable in the Variables tab (Second column, under the "States" panel)
Right-click on the text box and select Expose Variable
Enter the name "Text" for the variable name
You can verify that the Text
variable is exposed by clicking on the the Button component and seeing the Text
variable under the Exposed category:
Now that the Text
variable is an exposed variable, it can be changed on each Button instance. To do this:
Select one of the Buttons in MainMenu
Change its Text
to "Button 1"
Feel free to set different Text values on all of the buttons. Notice that the Text
may word-wrap.
This tutorial shows how to expose Text values per-instance. You can expose other instance variables in your components to customize instances. Other examples of variables which may be exposed include:
Visibility of icons on a Button component
Font sizes on a Label component
Sprite visibility showing the number of connected gamepads on a JoinGame component
Width (percentage) on a HealthBar component
It's best to experiment with exposed variables to get a feel for how you can use them in your own components.
Gum supports creating and previewing animations in the editor through the use of states. The general workflow for creating an animation is as follows:
Create states representing the keyframes in the animation (usually one category per animation)
Add an animation to the component or screen
Add states to the animation and adjust their time
Set interpolation values for each keyframe to control "easing"
Gum's animation system is very powerful and can be used in a variety of situations:
Animations which play when a screen or component is shown or hidden
Animations used to transition between behavior states such as changing a button from regular to highlighted state
Lengthy animations which can last multiple seconds for complex transitions
Animations are stored separate from the screen or component on the file system. If a screen or component contains at least one animation then Gum will save a Gum Animation XML file (.ganx extension) with the word "Animations" appended on the screen or component's name. In other words GameScreen would have a file called GameScreenAnimations.ganx in the same folder containing information about its animations.
Once an animation has been made it can be played back in editor. The following shows how an animation is played back, both in real time and also by dragging the slider.
Gum is an open source project so you can run it from source instead of running the pre-compiled project. Running from source is not a requirement, and is only needed if you intend to contribute to Gum or if you'd like to diagnose problems in a debugger.
Download the source file from GitHub
If you downloaded the .zip file from the GitHub main page, unzip the file
If you downloaded the file through a Git client, be sure to be on the master
branch
Locate the Gum.sln file
If you downloaded the .zip, it is in the root folder of the zip
If you cloned the repository, it is at the root of the Gum folder
Double-click it to open Visual Studio, or open Visual Studio and load the .sln
Run the build configuration in "x86". The build configuration may default to "Mixed Platforms". If you do not change it Gum will not compile.
If your project depends on plugins, be sure to build solution, rather than pressing F5. This guarantees that all plugins are built and copied correctly. For more information see below.
Gum depends on a number of plugins for its functionality. By default if you build the project and run it (such as by pressing F5 in Visual Studio), then plugins are not automatically built. To build plugins, you need to explicitly build all plugin projects. The easiest way to do this is to select the Build -> Rebuild Solution option in Visual Studio.
Gum is the best Game UI Layout tool available. It provides a flexible, efficient layout engine capable of producing virtually any layout. Gum can be used in a variety of contexts including in the FlatRedBall game engine, MonoGame, and Meadow. The Gum layout engine can also be included in any .NET project without requiring the use of a particular graphical API.
Gum UI includes advanced layout functionality to create and preview your UI
Gum allows the creation of components which can be instanced and customized in screens and other components
Adjust an object’s origin, position units, size units, and stacking to create fluid UI
Grab the NuGet, add a few lines of code, see your Gum project in game!
Gum objects can be created and modified in code. Create fully-featured UI by subscribing to common UI events.
Gum has been used in commercial projects of all sizes - check them out in our Showcase page.
Gum is actively maintained and provides lots of ways to get answers:
Check the rest of the documentation here
Join the Discord chat (shared discord with FlatRedBall)
Create an issue on Github
This page walks you through the basics of using the Gum UI tool, which we'll refer to simply as Gum for this and all other documentation.
Gum separates its elements into three categories: Screens, Components, and Standard. Behaviors are an advanced topic that we'll skip for these tutorials.
Standard elements represent the building-blocks for screens and components, and all projects use the same set of standard elements. To see the list of elements, expand the Standard tree item. Clicking on any element displays it in the preview window.
Sprite element is selected in the image above. Notice that since a SourceFile is not set, the Sprite renders as a red X.
Plugins can add additional standard elements. The list above is the default list of standard elements before plugins have made any changes.
Components are objects which can contain standard elements and instances of other components. Components can be very simple, such as a Label, or very complex, such as an options menu with dozens of instances. Items added to components or screens are called instances.
Screens are objects which can contain standard elements and instances of other components. Unlike Components, Screens cannot be added to other Screens. Screens exist mainly for organization. Screens can be simple, such as a loading screen, or complex such as a HUD in an RTS game.
Components and screens are similar - both can contain instances of standard elements, and both can contain other components. The only difference between screens and components is that screens cannot contain other screens.
For example you can think of screens in a video game which might include a main menu, credits screen, options screen, and level selection screen. You can think of components as elements which are composed of multiple standard elements. Examples include a Button component which is made up of a Sprite instance and a Text instance, or a Logo component which may be made up of multiple Sprites and Text objects.
To create a screen:
Right-click on the Screens tree item and select Add Screen
Enter the name of the new screen - such as MainMenu
Click OK. The newly-created screen is created and selected
Instances of standard and component elements can be added to screens and components. To add an instance:
Select the destination screen or component. For example, select the MainMenu screen
Push the left mouse button (but don't release it) on the Text item. If you happen to release the mouse button, this selects the Text item, so you need to re-select the destination (MainMenu).
Drag the Text item onto the Editor tab
Release the mouse button. A new text instance appears in your screen.
Alternatively, you can also drag+drop a standard element into a screen in the tree view.
If an element is dropped in the Editor window, it appears at the location where it has been dropped - setting its X and Y values. If an element is dropped in the Project tab, then it preserves its default X and Y values.
Once an instance is a part of a screen or component it can be edited visually in the preview window. The selected instance has eight (8) handles surrounding it. These are called the resize handles and can be used to change the selected instance's width and height.
In the case of the Text object, the resize handles are used to control how the text object performs line wrapping.
You can use the resize handles to resize the instance, or you can simply push the mouse button and drag inside the instance to change its position. Notice that an object's outline is displayed when the cursor is hovering over the instance.
This tutorial introduces the basics of working with standard elements and adding them to Screens. The next tutorial covers the Variables tab which can be used to access all element variables.
Gum Application (binaries): files.flatredball.com/content/Tools/Gum/Gum.zip
Gum Source Code: https://www.github.com/vchelaru/Gum
Currently the Gum tool requires XNA runtimes. Download and install the runtime prior to running Gum:
Since Gum is a prebuilt file in a .zip, Windows blocks the file which results in the "Windows protected your PC" popup:
You can click More info, then Run anyway. Alternatively, you can right-click on the .zip file and select the option to unblock:
Before proceeding, ensure that you have the following prerequisites installed on your macOS:
Homebrew
WINE
Winetricks
Install Homebrew
Homebrew is a package manager for macOS. If you haven't installed Homebrew yet, you can install it by following the instructions on the official Homebrew website.
Install WINE and Winetricks
You can install WINE and Winetricks using Homebrew. Open a terminal and run the following commands:
The following goes through the steps do download and run the setup_gum_mac.sh
automation script. This script goes through the steps for you with minimal interaction to setup your environment on macOS to run the GUM tool using WINE. If you would prefer to do this setup manually, please see the Manual Setup Steps section below.
Download the setup_gum.mac.sh script https://raw.githubusercontent.com/vchelaru/Gum/master/setup_gum_mac.sh
Open a terminal and cd
to the directory that the script was downloaded to
Make the script executable
Execute the script
The following goes through the steps setup your environment on macOS to run the GUM tool using WINE.
Open a new terminal
Install .NET Framework 4.8 using winetricks
with the following command:
This command initiates the installation of .NET Framework 4.8. A total of two installer dialogs appear one after another. Follow the steps for both to complete the installation. This process may take a several minutes, so please be patient.
Download the XNA 4.0 Redistributable MSI file from Microsoft. You can download it using the following command:
After downloading the MSI file, install it using the following command:
Follow the installation prompts. At the end of the installation, it may display an error related to launching DirectX. This is normal; just click "Close" on the error dialog.
Download the Gum Tool ZIP file from the FlatRedBall website and save it to your preferred location. You can download it using the following command:
Unzip the downloaded Gum Tool ZIP file into the Program Files directory of the WINE folder. Run the following command in the terminal:
After unzipping the Gum Tool, remove the downloaded ZIP file using the following command:
Create a script to run the Gum Tool. Run the following command in the terminal:
Make the script executable by running:
To ensure you can run the Gum Tool from any directory, add the script directory to your PATH.
For Bash SHELL
For ZSH Shell
Reload the shell configuration to apply the changes. Run the following command:
For BASH Shell
For ZSH Shell
Congratulations! You have now successfully set up the Gum Tool on macOS using WINE. You can open the Gum Tool by simply typing the following command in the terminal:
If the command doesn't work immediately, try closing and reopening the terminal.
The Gum Variables tab displays all available variables when editing an instance or element. While the Editor tab is handy for quick edits such as positioning and resizing instances, the Variables tab exposes all variables. It is also useful for making fine changes to instances, such as by moving an instance by a single pixel.
The Variables tab shows variables for the selected instance or element.
Variables can be edited by changing values on the selected variable. For example, to move the text to the right, change its X value to a positive number. Press Enter or Tab to apply the changes:
Gum provides a flexible positioning system. The position of an element is a result of a number of variables. We'll go over a few here.
By default all instances are positioned by their top-left corner. For example, setting the Text instance's X
and Y
to 0 aligned its top-left position to the top-left of the screen (which is identified by a dotted line.
We can change the origin of the Text object by setting its X Origin
and Y Origin
values. Notice that if X Origin
is set to Center
then the Text object is positioned by its center:
You may need to pan the view in the Editor tab to be able to see the Text object. Gum provides multiple ways to pan the view:
Press and hold the middle mouse button while the cursor is over the preview window. While the middle mouse button is down, move the mouse cursor.
Use the scroll bars on the bottom and side of the view
Hold down CTRL and press the arrow keys
Changing the X Origin
value changes the origin of the selected instance; however, it is still positioned relative to the top-left corner of the Text instance's container - which in this case is the entire screen designated by the dotted outline rectangle.
We can change the origin that the Text is relative to by changing the X Units
. By default the X Units
variable is set to Pixels From Left
and Y Units
is set to Pixels From Top
.
Changing the X Units
to Pixels From Right
causes the Text to be positioned on the right-side of the screen.
The X,Y, Origin, and Units values are all available for every type of element in Gum; however, these values only change the bounds. In the case of a Text object we may be interested in how the text is aligned within the bounds. The Text object offers two variables for aligning its text: Horizontal Alignment
and Vertical Alignment
. Changing the Horizontal Alignment
to Center
centers the Text within its bounds:
You may have noticed that some variables in the Variables tab have a green background while others have a white background. For example, in the image above the TextInstance's Vertical Alignment
is green. This is because instances are not required to define values for every variable. Whenever an instance does not set a variable value, it uses the value that is defined in the Standard Element definition.
To see in action, select the Text item under the Standard folder. Notice that all values have a white background. Keep in mind the the default values for Horizontal Alignment
and Vertical Alignment
:
If the default Horizontal Alignment
and Vertical Alignment
values are changed, the changes will immediately be reflected in the preview window for the default Text configuration:
Now if we select the TextIntance we will see that the Vertical Alignment
is using the Bottom
value; however the Horizontal Alignment
is still using Center
- this is because a value that is explicitly set on an instance will always override the default value set in the Standard element. Notice that Horizontal Alignment
has a white background (indicating a custom value) and Vertical Alignment
has a green background (indicating a default value).
Values can be reverted back to their default simply by right-clicking on the variable name in the Variables tab and selecting Make Default
Components can contain instances of other components and of standard objects. Examples of components include:
Check boxes
Buttons
Popup Menus
Components can also be simple such as a button or more complex UI elements such as a full Options screen with dozens of instances.
To understand how components work, we'll create a simple Button component. To do this:
Right-click on the Components folder in Gum and select Add Component
Name the Component "Button"
Drag+drop a ColoredRectangle standard element into the Button component
Drag+drop a Text standard element into the Button component
Since ColoredRectangleInstance and TextInstance are both white you may not be able to see the Text. Let's change the ColoredRectangleInstance's color:
Select ColoredRectangleInstance
Change Red
to 0
Change Green
to 0
Keep Blue
as 255
Notice that as you change the values, the background on the text box changes from green to white to indicate that the value has an explicit value. The Blue
text box keeps a green value since it has not been changed from its default value.
Now you should be able to see the Text on top of the rectangle:
At this point we have made some progress towards creating our first button, but it still needs some work.
First, we're going to adjust the size of the instances inside of our Button component. At this point you can see that the ColoredRectangle (the blue background) is not the same size as the button. Not only do we want to make the blue ColoredRectangle larger, but we also want it to automatically match the Button's size (the dotted outline).
To do this:
Select the ColoredRectangleInstance
Select the Alignment tab
Click the Fill Dock button
Alternatively you can adjust the individual values. Keep in mind that using the Alignment tab is the fastest way to get your instances setup. The next section shows all of the changes that the Alignment tab performs for you:
Select the ColoredRectangleInstance
Change Height Units
to Relative To Parent
Change Width Units
to Relative to Parent
Change Height
to 0
. This means that the actual height of the ColoredRectangleInstance matches the actual height of its container (the Button Component). Since Height Units
is set to Relative To Parent
.
Change Width
to 0
. This means that the actual width of the ColoredRectangleInstance matches the actual width of its parent.
Now the ColoredRectangleInstance automatically matches the Button's actual with and height:
Next we'll position the TextInstance. We'll want to adjust the Text so that it is always centered, and line-wraps with the size of the button.
To do this:
Select TextInstance
Click the Alignment tab
Set Margin to 20
Click the Fill Dock button
Alternatively you can set each individual value on the Text by following these steps:
Select TextInstance
Change its Horizontal Alignment
to Center
Change its Vertical Alignment
to Center
At this point the Text is vertically and horizontally centered within its boundaries, but we want to have the boundaries centered within the Button. To do this:
Keep TextInstance selected
Change the X Units
to Pixels From Center
Change the X Origin
to Center
Change X
to 0
Now let's make it centered on the Y as well:
Keep the TextInstance selected
Change the Y Units
to Pixels From Center
Change the Y Origin
to Center
Change Y
to 0
Finally, let's make the width of the text match the width of the button. For the Text we'll actually leave a border around the edge so the Text doesn't line wrap right against the edge of the button. To do this:
Keep the TextInstance selected
Change the Width Units
to Relative to Parent
Change Width
to -40
. This means the actual width of the Text is 40 pixels less than the actual width of its container. Since the button is centered this means a 20 pixel border on the left and 20 on the right (20+20=40).
Buttons are typically wider than they are tall. To match this common layout, let's set some variables on the Button:
Select the Button component
Change Width
to 120
Change Height
to 36
Notice that whenever you change these values, the contained objects (text and colored rectangle) adjust automatically.
Now that we have a component created, we can add instances of this component the same way we have added standard elements. To do this:
Create a new Screen. I'll call mine MainMenu
Drag+drop the Button component into the Screen
We can now resize and position the Button instance. We can reuse our Button component to create multiple instances. Each instance can be adjusted by changing its X
, Y
, Width
, and Height
values.
We can change top level variables on the Button such as X
, Y
, Width
, and Height
, but we cannot change variables on instances within the Button - all of our buttons currently display "Hello" text.
The next tutorial shows how to use exposed variables to further customize each button instance.
This article shows how to create an animated component. It will contain an animation which can be used when the component first appears.
First we'll create a component which will be animated. To do this:
Right-click on Components
Select Add Component
Enter the name TextComponent and click OK
Drag+drop the Text Standard into the TextComponent to create a Text instance
Select the Alignment tab and click the middle button to have the TextInstance fill the TextComponent
Now that we have a component we'll add the states needed for animation. We'll add all states in a category called HideShow. Animation states should always be categorized. To create the states:
Right click in the States list box
Select Add Category
Enter the name HideShow
Right-click on the HideShow folder
Select Add State
Enter the name Hidden and click OK
Right-click on the HideShow folder
Select Add State
Select Shown
Now that we have the states defined we can set values for the states. In this case the only thing we'll be modifying is the TextInstance's Font Scale value. To do this:
Select TextInstance
Select the Hidden state
Set the Font Scale to 0. This makes the Text so small that it's invisible
Select the Shown state
Verify the Font Scale is 1, or set it to 1 if not. This makes the Text regular size
The two states we created above will be used as the keyframes for our animation. The animation will begin in the Hidden state then interpolate to the Shown state. To add this animation:
Verify that TextComponent or any objects under it are selected
Select View -> View Animations
The Animations tab appears in the bottom right
Click the Add Animation button
Name the animation Show and click OK
Select the Show animation and click Add State
Select the Hidden state and click OK - this is the first keyframe in our animation
Click Add State again
Select Shown and click OK
The animation can now be played or previewed:
The Interpolation Type value sets how one keyframe blends to another. By default keyframes use Linear interpolation, which is a constant change from one state to another. When interpolating from one keyframe to another, the first keframe defines the interpolation type. In our case the Hidden frame defines the interpolation type. We can change the Interpolation Type and preview the animation:
Select the Hidden keyframe
Change Interpolation Type to Elastic
Playing the animation will reflect these changes.
States allow you to set multiple variables at one time. Examples of states might include:
A button with Regular, Highlighted, Pressed, and Disabled states
A game logo in Large and Small modes
A game HUD which can appear on and off screen
This tutorial builds upon the previous tutorial where a Button component was created. If you haven't yet, you should read through the earlier tutorials to create a Button component.
First we'll define two new states. All components and screens have a Default state automatically. This Default state is uncategorized, but all other states must be in a category. Therefore, we'll first add a new category:
Right-click in the States tab
Select Add Category
Enter the name ButtonStateCategory
To add a new state:
Right-click on ButtonStateCategory
Select Add State
Enter the name "Highlighted"
Click OK
The Button component now has a new state called Highlighted:
Once a state is defined and selected, setting a variable associates that variable with the selected state. In other words, any variable that is set when the Highlighted state is selected results in that variable being added to that state.
For this example, we can make the button become a lighter blue when highlighted. To do this:
Verify the Highlighted state is selected
Select the ColoredRectangleInstance
Set the Green
and Red
values to 100
Notice that the Green and Red values are rendered with a white background rather than green - indicating that they are explicitly set in the Highlight state.
Be careful when editing objects with multiple states. You may end up making changes without realizing that you are doing so in the wrong state.
The values that have just been set apply only to the state that was selected when the changes were made - the Highlight state. This means that clicking on the Default state switches the button back to the default colors. By clicking on the states in Gum you can preview and edit states easily.
Whenever a state in a category sets a variable, that variable is set across all states in that category. So far this tutorial only created a single state called Highlighted, but if additional states are set, all will explicitly set the Red
and Green
variables. This topic is covered in more detail in the next tutorial.
Gum supports creating animations which can play other animations. This is especially useful when creating animations in Screens that contain components which themselves have animations. This tutorial will build upon the previous tutorial where we created an animated component called TextComponent.
First we'll create a Screen called AnimatedScreen. To do this:
Right-click on Screens
Select "Add Screen"
Enter the name "AnimatedScreen" and click the OK button
Drag+drop a few TextComponents into the Screen and spread them out visually
The animation we will be creating in our Screen will start with all TextComponents being invisible, then each one appearing by playing their Show animation. The animations will be slightly staggered. First we'll add the initial state where all of the TextComponents are invisible. To do this:
Verify that the AnimatedScreen is selected
Right-click in the states area and select "Add Category" name it "ScreenCategory"
Right-click the category and select "Add State"
Name the state "AllInvisible" and click OK
Click to select the "AllInvisible" state.
Select one of the TextComponents
Set its HideShow State to Hidden
Repeat setting the State to Hidden for the other TextComponents
Now we have all of the states and animations that we'll use as keyframes in our animation. To create the animation:
Select AnimatedScreen
Select "View" -> "View Animations"
Click "Add Animation"
Name the animation "ShowAll"
Select the ShowAll animation
Click "Add State"
Select "ScreenCategory/AllInvisible" and click OK
The animation now sets all TextComponents to their Hidden state initially.
Next we'll be adding animations to animate the TextComponent instances to visible. To do this:
Bring up the animation window for AnimatedScreen if it is not already showing
Select "ShowAll"
Click "Add Sub-animation"
Select the first TextComponentInstance
Select the Show animation and click OK
Select the newly-created animation and set its Time to 0.5
Repeat the above steps to add animations for the other two TextComponents, but set their times to 1.0 and 1.5
Now the animation can be played or previewed with the slider bar:
Gum supports loading image files for Sprites and NineSlices. This tutorial discusses how to load files, and how they are referenced in Gum.
First we'll set up a workspace:
Create a Screen called SpriteScreen.
Drag+drop a Sprite into the newly-created Screen
The Source File
property is the image that the Sprite displays. Usually Source Files
are of the .png file format. To set the source file:
Select SpriteInstance
Find Source File
in the Variables tab
Click the "..." button to bring up a file window
Navigate to the location of the file you would like to load
Click "Open" in the file window
Once Source File
is set, the Sprite displays the image in the Editor tab
If you select a file which is not located in the same folder or a sub folder of your gum project, Gum asks if you would like to reference the file in its original location or create a copy.
Usually it's best to copy the file to the Gum project folder so that the Gum project can be moved to different computers without breaking file references.
Sprites can display portions of their Source File
. Files which combine multiple images are often called sprite sheets or tile sheets, and are commonly used in game development to keep art organized and to improve performance.
For example, the following file contains images for an animated character, ground tiles, and other entities for a platformer game.
If we download this file and set it as our , then the sprite displays the entire file.
We can display a portion of the Sprite rather than the entire file:
Click on the Texture Coordinates tab
Check the Snap to grid option to make it easier to select a region
Double-click anywhere on the image to select a region around the cursor
Move the selected region to the desired location to adjust the sprite's texture coordinate values
Gum provides simple controls for centering objects inside of their parents. This page shows how to center objects in a variety of situations. For brevity this document uses vertical centering, but the same concepts apply to horizontal centering.
The easiest way to center an object is to use the center Anchor. This sets all of the values necessary to center an object both vertically and horizontally.
Objects can be centered by setting their unit and numerical values. The Alignment tab is a shortcut for these values, but we can assign each value individually so an object is centered vertically:
Set Y
to 0
Set Y Units
to Pixels from Center
Set Y Origin
to Center
Centering can be performed with margins by adding an additional container to create the necessary margins. For example, consider a situation where we want to center the green rectangle inside the blue rectangle, but leave a 32 pixel margin at the top.
We may want something similar to the following image:
To do this, an additional container can be added as shown in the following image:
In this case, the container has the following relevant properties:
Y
= 0
(so it is pressed against the bottom)
Y Units
= Pixels From Bottom
(so it is bottom justified)
Height
= -32
(leaving a 32 pixel margin)
Height Units
= Relative to Parent
(so that it always has a 32 pixel margin regardless of parent size)
The green rectangle can be added as a child to the container, and then centered within the container. This results in the green rectangle always being centered within the area that leaves a 32 pixel margin at the top even if the main rectangle is resized, as shown in the following animation:
Additional margin can also be added to the bottom by changing the container's Y value. For example, a 20 margin border can be added at the bottom, leaving a 32 pixel margin at the top by setting the following values on the container:
Y
= -20
(move the bottom of the container up by 20 pixels)
Height
= -52
(leaving a 32 pixel margin at the top, and accounting for the container being moved up an extra 20 pixels)
Bottom-up stacks can be used to display stacks of elements which should move up as more are added. This concept is similar to messages received in a chat window. Gum layout can be used to produce this type of stack.
This example shows a bottom-up stack (vertical) but the same approach could be used to create a right-aligned stack.
Items in a bottom-up stack need a parent Container. This Container could be an instance of a Container or a component since components usually have their Base Type
set to Container. For this example we'll use a container.
This container to stack needs the following variables set:
Children Layout
set to Top to Bottom Stack
so all children stack vertically
Height Units
set to Relative to Children
so the container resizes itself as more children are added
Height
set to 0
so the effective height of the container is based purely on its children
Stack Spacing
set to 2
(optional) to add spacing between each child
Now children of the Container stack vertically. This concept works for any type of child, but we'll use ColoredRectangles for this example. Add a few instances to the Container and they stack vertically.
Finally we can have the stack grow up instead of down. To do this, change the following variables on the parent container:
Y Origin
set to Bottom
Y Units
set to Pixels from Bottom
Now as new children are added, the parent stack grows and all items shift up.
The Clips Children
property controls whether children of a component or container can render outside of the bounds of their parent. By default this is false, which means that all children are not clipped (can fully-render) regardless of whether they are within the bounds of their parent or not. Setting this value to true prevents children from rendering outside of the bounds of their parent.
The Base Type
variable can be used to specify both inheritance but also the type of an instance.
Base Type
on an instance indicates its type. This is usually automatically set when an instance is first created - usually by drag+dropping a component or standard element onto its target component or screen.
Gum Screens and Components support changing Base Type
to specify inheritance. By setting Base Type
, a screen or component automatically inherits the following:
Variable values
Exposed variables
Instances
Available variables, such as stacking if inheriting from a container
Inheritance is useful if your project needs multiple screens or components which share common variables or instances.
All instances must have a Base Type
set. For example, the following instance is of type Container.
Base Type
is automatically assigned when a new instance is created. For example, the following animation shows a new ColoredRectangle instance created. Note that its Base Type
is automatically assigned to ColoredRectangle.
Base Type
can be changed after an instance is created. Keep in mind that doing so does not change its name or any other properties, so you may need to manually adjust properties when converting between different Base Types
. Also, note that default values may change when switching from one Base Type
to another.
The following shows a ColoredRectangle changed to a Container. Since Container and ColoredRectangle have different default Width
and Height
values, changing Base Type
results in changes to default size too.
All components use inheritance even if their Base Type
variable is not set explicitly. By default components inherit from the Container type.
By inheriting from the Container type, components have access to all Container variables such as Children Layout.
Components can inherit from standard types. For example, instead of inheriting from Container a component may inherit from ColoredRectangle. By doing so, it has access to all properties on the ColoredRectangle type.
Most components inherit from the Container type. If a component needs to display visuals, such as a ColoredRectangle, typically the ColoredRectangle is added as a child to the component rather than being used as a Base Type
.
Components can inherit from other components. By doing so the component inherits all children and exposed variables from its base component.
A component which inherits from another component is often called a derived component. The component which is being inherited from is often called a base component.
A base component can be used to define instances which the derived component can modify. For example a component named ButtonBase may define that all components have a ColoredRectangle named Background and a Text named TextInstance.
If another component uses ButtonBase as its Base Type
, then this component automatically gets Background and TextInstance children which match the base instances.
The CancelButton can modify variables on the added children. For example the CancelButton can modify the Text on the TextInstance and the color values on the Background.
The derived component has the following restrictions when working with children instances:
Name cannot be changed. For example Background must always be named Background.
Base Type cannot be changed. For example, the base type for Background must be ColoredRectangle
Children defined in the base cannot be removed. For example, the Background child cannot be deleted from CancelButton. Children can be made invisible.
If the base type adds new instances, then the derived types automatically get the same instances added as well. Similarly, if the base type deletes a child, then the child is also removed from the derived type.
Derived types get access to all of the exposed variables in the base type. For example, if ButtonBase exposes the TextInstance's Text property, this is also available on the derived component.
Base Types
allow for the customization of a component, including the creation of many variants. Similarly, States also allow for the customization of a component in similar ways. When deciding between whether to use states or inheritance, keep the following in mind:
States are often used to set variables temporarily, while inheritance is permanent. For example, a button may set its background color values in response to being highlighted. By contrast, a Cancel button may always say "Cancel".
States do not allow for the creation of new instances. Although derived components cannot delete children which are defined by their Base Type
, derived components can add additional instances.
Components can use multiple categories. Therefore, it may not be clear which category defines the type of component. A component can only have one Base Type, so its type is defined clearly.
States are a powerful way to create expressive groups of variables. Some UI elements may require a combination of states to be applied simultaneously.
For example, consider a Button component which displays a button callout.
This button might be a standard Button with the following states:
Enabled
Disabled
Highlighted
Pushed
But it may also have states for which button icon to display:
A
B
X
Y
LeftStick
RightStick
These two sets of states could be set independently and combined at runtime. Categories let you create groups of states so that multiple states can be set simultaneously.
For this tutorial we'll create a new component. This component has state categories for size and for color. To do this:
Open Gum
Create a new Component called CategoryDemo
Right-click anywhere in the State box and select Add Category
Enter the name "Size" for the new category and click OK
Repeat the above steps to create a "Color" category
Now we can add states to the categories. To do this:
Right-click on the Size category and select Add State
Enter the name "Small" for the new state
Right-click on the Size category again and select Add State
Add a second state to "Big"
Right-click on the Color category and select Add State
Add a state called "Red"
Right-click on the Color category again and select Add State
Add a state called "Blue"
Now that we have states set up we need to add a visual element to the component so that we can see our changes.
To do this, select the Default state and drag+drop a ColoredRectangle into your component
To modify a state, you can select it and edit in the Editor tab or change properties in the Variables tab to modify what the state sets. Notice that normally for a component like this the ColoredRectangleInstance would have its width and height be relative to its container, but we're not doing this for the sake of keeping the tutorial shorter.
First we'll set the Size states. To do this:
Select the Big state
Resize the colored rectangle so it is larger than the default
Select the Small state
Resize the colored rectangle so it is smaller than the default
Next we'll set the Color states. To do this:
Select the Red state
Set the Red
, Green
, and Blue
values to: 255
, 0
, 0
Select the Blue state
Set the Red
, Green
, Blue
values to: 0
, 0
, 255
Now that we have our CategoryDemo component set up with multiple categories, we can view these states on any CategoryDemo instance. To do this:
Create a Screen called "CategoryDemoScreen"
Drop an instance of the CategoryDemo component into the CategoryDemoScreen
Select the newly-created CategoryDemoInstance
Scroll down in the Variables list and notice that the instance has drop-downs for each category.
You can set each state independently and the states combine
We can revert the states back to their unset values by right-clicking on the state variable and selecting the Make Default item.
If a variable is modified in one of the states in a category, then all of the states in that category are automatically assigned the default value, and this value is explicitly set. This concept makes working with states far more predictable.
For example, consider a component which has:
A single ColoredRectangle
A category called RectangleSizeCategory
States called Big, Medium, and Small
Initially, all states in a category do not explicitly assign any variables. We can see this by selecting the category and observing the Variables tab.
If a variable is changed in one of the states in the category, then that variable propagates to all other states, and the Category lists this as one of the variables that it modifies.
For example, we can select the Big category and change the ColoredRectangle.Width property to 150.
Once this value is changed, the RectangleSizeCategory lists this as a variable that it modifies in the Variables tab.
If we select any of the other states in the category, they show that they explicitly set the Width value as well (the value has a white background instead of light green). The value is inherited from the default state.
Once a variable is set in a category, all states are required to set this value. A variable cannot be removed from a single state in a category. Rather, to remove a variable, all states in the category must remove the variable. This can be done by selecting the category and pressing the X button next to the variable name.
The Parent
variable allows UI elements to be positioned and sized according to other UI elements. Parenting hierarchies can go many levels deep and the parent/child relationship can be visualized by the white line connecting the parent to the child when the child is selected.
Parents control control the position of their children. Parents can also control the size of their objects depending on the child's Width Units
and Height Units
.
For example, if a parent is moved, its children move along with it. For more information on positioning children, see the X Units and Y Units pages.
Children can also be sized according to their parents. For more information on sizing children according to their parent, see the Width Units and Height Units pages.
Children can be placed outside of their parent's bounds. In the simplest case, a child can be dragged outside of its parent's bounds in the editor.
Children outside of their parent's bounds still follow all of the same rules for sizing and positioning, but there are some important things to keep in mind.
Children placed outside of a parent do not affect the parent's effective width or height. Any unit value that depends on children or parents only considers the immediate child or parent and does not look at sizes beyond the immediate relationship.
For example if a parent has 100 effective width, and its child is given an X
of 200, the parent's effective width remains 100 (assuming the parent does not size itself according to its children). This is important when other children are sized or positioned according to the parent's width.
The following animation shows three instances:
A parent container
A blue rectangle which is sized according to the parent rectangle
A yellow rectangle which is moved outside of the bounds of its parent
Notice that when the parent resizes the blue rectangle is also resized, but when the yellow rectangle is moved outside of the parent bounds, the parent and blue rectangle are not resized.
Children outside of bounds may not respond to click events unless the parent is explicitly checking for click events outside of its bounds. This is a property which is set at runtime. For more information see the RaiseChildrenEventsOutsideOfBounds page.
To change Parent
in the Project tab:
Select a child
Drag+drop the child onto the desired parent
The child can be detached from its Parent
by drag+dropping it onto the Component.
Drag+dropping onto a parent may set the Parent
property to an instance inside of the parent's Component type sets its Default Child Container value. For more information see the Default Child Container page.
To set Parent by name:
Select the desired child
Change the Parent
property to the desired parent:
The Locked
property controls whether an instance can be clicked in the preview window. If this value is true, then the instance cannot be clicked on directly, but must instead be selected through the Project tab.
The behavior of the Locked property will change in future versions of Gum as defined in this issue: https://github.com/vchelaru/Gum/issues/273
Once a locked object is selected it can still be edited normally, both in the Variables tab and in the Editor tab. Locking an instance prevents accidental selection in the Editor tab.
The Locked
property does not have any impact on the behavior of Gum objects at runtime, such as when running in FlatRedBall or MonoGame. This property only affects editor behavior.
Rotation
can be used to rotate Gum components. Rotation is measured in degrees, where positive values rotate an object counterclockwise about its origin (X Origin and Y Origin).
An object is rotated about its origin, which by default is its top-left corner:
Objects can also be rotated visually by grabbing the rotation handle:
Holding the SHIFT key snaps angles to 15 degree increments.
The X Origin and Y Origin properties define the point of rotation for an object. The following animation shows how changing origin values can affect rotation.
Height Units
controls how a unit is vertically sized, which may be relative to its parent. By default most types uses Absolute
height, where each unit represents 1 pixel of height in pixels. When using Absolute
, an object ignores its parent's Height.
The following shows a child ColoredRectangle with 50 Absolute
Height:
Text instances which use an Absolute
height of 0 size themselves to be the height of their contained text. This behavior will likely change in future versions of Gum so this combination is not recommended. Instead, to size a Text instance according to its contained text, Set Height Units
to Relative to Children
.
The following shows a child ColoredRectangle with -10 Relative to Parent
Height, which means is sized 10 pixels less tall than its parent.
All relationships between parent and children depend only on the direct parent or child. Grandchildren and grandparents are not considered when performing calculations. For more information, see the Parent page.
The following shows a child ColoredRectangle with 100 Percentage of Parent
, which means it has 100% of the height of its parent. Note that 100 Percentage
is the same as 0 Relative to Parent
:
Ratio of Parent
can be used to fill available space or to share available space with other objects using a ratio.
The simplest case is a single child in a container with its Height Units
set to Ratio of Parent
.
In this case the blue ColoredRectangle has no siblings (its parent has no other children), so it occupies the entire parent height. If a second child is added (by copy/pasting the existing child), then each child is given 1 ratio value, which means each is 1/2 of the size of the entire parent.
To better visualize the effect of ratio, it's common to set the parent's Children Layout to Top to Bottom Stack
, and to give each child a different color as shown in the following image.
As more children are added, each child's height is adjusted to make room for the new children.
Ratio values are distributed among all siblings using Ratio of Parent
proportionally. The image above shows four siblings, each given 1/4 of the ratio. If one of the the ratios changes (such as by increasing the second sibling's Height value to 3), then all siblings adjust in response to this change.
In this case, the total ratio is 6 (1 + 3 + 1 + 1), so the red is given 3/6 (1/2) of the parent's height, while each of the others is given 1/6 of the parent's height.
Values of 0 are supported, resulting in the object drawing with an absolute height of 0.
Ratio of Parent
is calculated after accounting for the height of children which are using absolute height. For example, if the height of the first child is 80 with a Height Units
of Absolute
, then the other three shrink to give the first the necessary room.
This effect can also be seen by adjusting the height using the handles.
Gum ignores invisible objects when calculating available space for Ratio of Parent
units. Therefore, if a sibling is invisible, Gum treats it as if it has 0 height which allows all other ratio siblings to expand.
Ratio of Parent
also respects Stack Spacing. A Stack Spacing
value greater than 0 removes the available space for all children with a Height Units
of Relative to Parent
.
The following image shows a child ColoredRectangle with 50 Relative to Children
Height
, which means that it is 50 pixels taller than is necessary to contain its children. Since the rectangle has no children, this is the same as having 50 Absolute
Height
:
Relative to Children
can be used to size an object based on the position and sizes of a parent's children. The following image shows a container with 0 Relative to Children
Height
, which means that its height is set just large enough to contain its children. Notice that if the children are moved, the parent's height adjusts. Both children are considered so the container adjusts its height according to the bottom-most side of either child:
A non-zero Height
when using Relative to Children
can be used to add additional padding to a parent container. The following animation shows how changing the height can adjust the absolute height relative to children:
A parent container can ignore its children when it determines its own height when using a Height Units
of Relative to Children
if any of the following are true:
The child's Ignored By Parent Size
is true.
The child's height depends on its parent's height. This circular dependency is resolved by the parent ignoring this child.
The child is explicitly positioned outside of parent's bounds
The child's Y Units
is Percentage of Parent Height
If a child has its Ignored By Parent Size
set to true, then the parent ignores this child when calculating its own size. For more information, see the Ignored By Parent Size page.
If a child's height depends on the parent, then the child is ignored by the parent. Once the parent has determined its own height, then the child is sized according to the parent. This type of circular dependency is common when adding background visuals to a container.
For example consider a container with two children - BlueRectangle and YellowRectangle - with the following variables:
BlueRectangle Y
= Pixels from Top
BlueRectangle Height Units
= Absolute
YellowRectangle Height Units
= Relative to Parent
Only YellowRectangle depends on its parent.
Since BlueRectangle's absolute height value does not depend on the parent, the parent can use BlueRectangle's absolute height when calculating its own absolute height. Since YellowRectangle depends on the parent, the parent ignores the YellowRectangle. Instead, YellowRectangle depends on the parent container's absolute height for calculating its own absolute height. This in effect creates a situation where BlueRectangle affects the height of both its parent and also its YellowRectangle sibling.
A parent does not consider a child if the child is explicitly positioned outside of the parent's bounds. This can happen if the child's Y Units
and Y
values result in the child being drawn outside of the parent's bounds.
If a child has Y Units
of Pixels from Top
and its Y
value pushes the child out of the top of its parent, then the portion that is outside of the top of the parent is ignored. The BlueRectangle in the following image has an absolute height of 50. Its Y
value is -20, so only 30 pixels are used to determine the parent's height.
Similarly, if a child uses a Y Units
of Pixels from Bottom
then the parent does not consider the height of any portion which is outside of its bounds. The following animation shows RedRectangle placed outside of the bottom of its bounds with a Y Units
of Pixels from Bottom
.
Notice that if RedRectangle is moved so that it is inside the bounds, it can affect the absolute height of the parent. As RedRectangle is moved into the bounds, the parent grows to accommodate the desired RedRectangle Y
value.
If a child is a Text instance using a Y Origin
of Baseline
and a Y Units
of Pixels from Bottom
, then portions of the text which fall below the baseline are ignored by the parent's height.
A parent ignores its child if the child uses a Y Units
of Percentage of Parent Height
because this also creates a circular dependency (parent height depends on child position, child position depends on parent height).
If a parent sets its Height Units
to Relative to Children
, then it must resize itself to contain its children. Normally, the height of the entire parent is determined by the child which needs the most space vertically. If the parent uses an Auto Grid Vertical
layout, then the children control the size of the cells rather than the entire parent. Since all cells must be the same size, the child which needs the most amount of space vertically determines the height of all cells.
For example, the following image shows a four by four grid, each containing one white rectangle. The first rectangle has an Absolute
Width
and Height
of 100, so each cell is sized to be 100x100. Note that the other rectangles are 50x50.
The largest child determines the cell size for all other children. Therefore, if a child is moved or resized so it outgrows its cell, then the parent height adjusts in response.
The term "children" can refer to:
Instances added to a parent, such as ColoredRectangles added to a Container
Individual letters in a Text instance - each letter and line of text can expand the height of its parent
The following animation shows a Text instance which has its Height Units
set to Relative To Children
. As more lines of text are added, the Text automatically expands in size.
The height of a Text instance using Relative to Children
depends on the number of lines displayed by the Text instance and the maximum line height given the current font properties. Therefore, the height of a Text stance remains the same regardless of the contents of a single line.
For example, the following image contains multiple Text instances. Each has a single line of text, but the line of text differs in the height of each character. Notice that the texts are all the same height even though the contents of their lines differ.
We can observe the absolute height of a Text instance by mousing over one of the handles for resizing vertically.
In this case, the height is 41 pixels tall. This is based on the lineHeight as defined on the .fnt file. The image above is using an Arial 36 font which has a lineHeight value of 41 pixels.
Percentage of Width
adjusts the object's effective height so it remains proportional to the Width
value multiplied by the Height
value (as a percentage). For example, if a Height
value of 200 is entered, then the effective height is 200% (2x) of the Width
.
The following image shows a child ColoredRectangle with a Height
of 200 Percentage of Other Dimension
. In this image, the Width
value is 50 units, so the effective height is 100 units:
Sprites can select a Height Units
called Percentage of File Height
, which sets the height of the Sprite according to the file that it is displaying. This is the default Height Units
for Sprites.
The following image shows a child Sprite with 200 Percentage of Source File Height
, which means it draws two times as tall as its source image:
This value depends on the Sprite's Texture Height
property, so changing Texture Height
also changes the Sprite's absolute height.
Sprites can select a Height Unit
called Maintain File Aspect Ratio Height
which sets the height of the sprite so its aspect ratio matches its source file multiplied by the Height
value. Usually Maintain File Aspect Ratio Height
is used with a Height
value of 100 so that the Sprite shows is source file at the correct aspect ratio.
Svgs also support using Maintain File Aspect Ratio Height
. For more information on using Svgs see the Skia Standard Elements page.
When this value is used, a Sprite's Width
can be changed resulting in its absolute height also changing.
When using Maintain File Aspect Ratio Height
, the Sprite's absolute height depends on the Sprite's Texture Height
property.
The Visible
variable controls whether an object and its children appear.
Setting Visible to false hides the selected instance.
Setting a parent's Visible
variable to false also hides all children. Note that this does not explicitly set the Visible property to false for all children, but a child's effective visibility depends on its parent.
If an instance is part of a parent which stacks its children (has a Children Layout
of Left to Right Stack
or Top to Bottom Stack
), then it will no longer be considered when stacking siblings if it is invisible. In other words, making an item invisible removes it from the stack.
If the stack contains children which use a Width Units
of Ratio
, then hiding any of the siblings results in the children with ratio width adjusting to occupy the extra space.
An invisible object can be selected by clicking on it in the Project tab or in the Editor tab.
Visible items are given preferential selection even if they are ordered behind invisible items.
Variable References
allows any variable on an instance or component to reference other variables. These other variables can be on the same instance or component, a different instance, or even variables from a different component.
One common use of Variable References
is to create a centralized style component which can be referenced throughout a Gum project.
Variables which are assigned through Variable References
cannot be directly set on the instance - the value obtained through the reference overwrites any custom value. For example, the reference Height = Width
results in Height being read-only and depending on Width.
Variable References
can contain multiple lines. Each line is a separate variable reference. Each variable reference uses the following syntax:
{VariableName} = {Components or Screens}/{ComponentOrScreenName}.{InstanceName}.{VariableName}
The variable being assigned is also called the left side and the variable on the right side of the equals is also called the right side. The right side only needs to include the component name if the right side comes from a different component. If the variable being assigned is from the current component, then no instance name is needed, only the variable name.
The following examples show how variables can be assigned:
Component
X = Y
The selected component's X variable references its Y variable
Component
Width = ContainerInstance.Width
The selected component's Width variable references the Width variable on an instance named ContainerInstance
Component
Width = Components/OtherComponent.Rectangle.Width
The selected component's Width variable references the Width variable on an instance named Rectangle inside a different component named OtherComponent
ContainerInstance (instance)
X = Y
The selected instance's X variable references the X variable of the element that it is a part of. Note that Y means the Y of the containing element.
ContainerInstance
Width = ContainerInstance.Height
The selected instance's Width variable references its own Height variable.
ContainerInstance
Width = Components/OtherComponent.Rectangle.Width
The selected instance's Width variable references the Width variable on an instance named Rectangle inside a different component named OtherComponent
The following example creates a Styles component which contains a color value which is referenced by objects in a MainMenu Screen.
Any component can serve as a centralized location for styling, but we use the name Styles by convention.
The Styles component can contain as many objects as are needed to style your project. Additional objects can be added to help indicate how things are used visually. For example, we include a Text object to indicate the red color is the Primary Color.
The color value can be referenced by any other object including objects in different screens or components.
To add a variable reference:
Select the object which should have a variable reference
Click inside the Variable References text box
Type the variable reference. The format of the variable reference is
{VariableName} = {Components or Screens}/{ComponentOrScreenName}.{InstanceName}.{InstanceVariable}
For example, to reference the Red variable in the Styles component, the syntax is
Red = Components/Styles.PrimaryColor.Red
Since color values have three components (Red, Green, and Blue), then all three components must be referenced. In this example, the background can reference the three colors with the following assignment text:
The types of the objects that contain the Variable References or which are being referenced do not matter. For example, a Text object could have its color values depend on the color values defined by a ColoredRectangle in the Styles component.
Once Variable References are set, the referenced instances (instances in Styles) can be changed and the changes will immediately propagate throughout the entire project.
As shown above, Variable References can be used to assign one variable to another. If a variable is referenced, then the variable cannot be manually assigned. The Variable Reference takes priority. For example, if an object references the Red, Green, and Blue variables, then those values cannot be manually set on the object. The values appear disabled and text indicates why they are read-only.
When entering a variable reference, Gum understands implied variable references by filling in the left-side of the equals sign to match the variable name on the right-side. For example, the following can be entered in the Variable References text box:
Gum automatically adds Red =
before the entry, as this is the most likely variable assignment. This addition happens when the text box loses focus, such as when Tab is pressed or when a different text box gains focus.
Assigning color values is a common part of styling, so to help with this situation, Gum also expands the "Color" variable into all three components when the Variable References text box loses focus. For example, the following text can be used to assign all three values at once:
When the Variable References box loses focus, this is expanded to the following assignments:
The examples given above are useful for a centralized styling scenario. Variable references do not require referencing variables from other Screens or Components. If a reference is between two instances in the same Screen or Component, then the variable reference does not need to include the name of the component.
For example, we can assign the X value of one ColoredRectangle (RedRectangle) to the X value of another ColoredRectangle (BlueRectangle) using the following assignment:
This assignment forces the RedRectangle's X value to match the BlueRectangle's X value.
Changing the BlueRectangle's X value automatically updates the RedRectangle's X, even though the two rectangles have no other relationship to each other (such as a parent-child relationship).
Typing a variable name can be tedious, especially when referencing a variable in a different Screen or Component. Qualified variable names can be obtained by right-clicking on the variable name in Gum and selecting the Copy Qualified Variable Name option. This can then be pasted in the Variable References box of any other object.
Usually a variable references the same-named variable from the source, such as Red being assigned to Red. This is not a requirement, and variables can reference other variable values. For example, the Green value could reference the Red value on a source.
Although this is not common, referencing different variables can help create complex UI elements.
The X Origin
variable controls the point which an object is positioned by. By default the X Origin
is Left
. X Origin
is shown visually as a white "X" in the editor.
The following image shows a ColoredRectangle with its X Origin
set to Left
:
The following image shows a ColoredRectangle with its X Origin
set to Center
:
The following image shows a ColoredRectangle with its X Origin
set to Right
:
The X Units variable controls how a unit is horizontally positioned relative to its parent. By default an object is positioned relative to the left of its parent, where each unit represents 1 pixel.
The following shows a child ColoredRectangle positioned 50 Pixels From Left relative to its parent:
The following shows a child ColoredRectangle positioned 50 Pixels From Center relative to its parent:
The following shows a child ColoredRectangle positioned 50 Pixels From Right relative to its Parent:
The following shows a child ColoredRectangle positioned 50 Percentage Parent Width relative to its Parent. In other words, it will be positioned halfway between the left and right edges of the Parent:
The Y Units
variable controls how a unit is vertically positioned relative to its parent. By default an object is positioned relative to the top of its parent, where each unit represents 1 pixel downward.
The following image shows a child ColoredRectangle positioned 50 Pixels From Top
relative to its parent:
The following image shows a child ColoredRectangle positioned 50 Pixels From Center
relative to its parent:
The following image shows a child ColoredRectangle positioned 50 Pixels From Bottom
relative to its parent:
The following image shows a child ColoredRectangle positioned 50 Percentage Parent Height
relative to its parent:
Pixels From Baseline
positions a child relative to the parent's baseline. If the parent is a Text instance, the baseline is the Y position of the bottom of letters which do not have descenders. For more information on the concept of text baseline, see the baseline Wikipedia page https://en.wikipedia.org/wiki/Baseline_(typography)
The following image shows a child ColoredRectangle positioned 0 pixels relative to a Text instance's baseline.
When using Pixels From Baseline
, the position depends on the font size, baseline definition in the .fnt, and whether the text wraps. For example, changing the Width
of the Text causes line wrapping which shifts the baseline.
A text instance's baseline is defined by its Font
and Font Scale
values. These values ultimately create a .fnt file with a base
value indicating the distance from the top of the text instance to the baseline. For example, an Arial font with Font Size 40 has a base
value of 36 and a lineHeight of 45.
This means that 36 pixels fall above the baseline, and 9 pixels (45 - 36) below.
Note that if the parent is not a Text instance, then the bottom of the parent is used as the baseline. The following image shows a Colored Rectangle using a Y Units
of Pixels From Baseline
with a Container parent.
Children in a Screen, Component, or parent instance are drawn top-to-bottom, so that children further down are drawn on top.
Gum provides a number of ways to reorder instances.
Items can be right-clicked in the editor to change their order.
Bring to Front - reorders the instance so that it is in front of all of its siblings.
Move Forward - moves the instance in front of the sibling that is in front of it. In other words, moves the item forward by one index.
Move In Front Of - moves the instance in front of the selected sibling.
Move Backward - moves the instance behind the sibling that is currently behind it. In other words, moves the item backwards by one index.
Send to Back - reorders the instance so that it is behind all of its siblings.
Items can be re-ordered in the Project tree view by holding the alt key and pressing up or down.
Gum uses a hierarchical ordering which means that a parent and all of its children draw before any of the siblings of the parent. For example, a container and all of its children draw before any other siblings of the container.
The following animation shows a container named ContainerInstance2 which draws on top of ContainerInstance1. All children of ContainerInstance2 also draw on top of children of ContainerInstance1.
If a parent is reordered, then all of its children also respect the new order. For example, if ContainerInstance2 is sent to the back, then all of its children draw below ContainerInstance1 and its children.
If a parent uses a stack or grid layout for its Children Layout variable, then the order of the children in the Project tab determines their order in the stack or grid.
For more information, see the Children Layout page.
The Default Implementation property can be used to indicate which component is the default implementation for a behavior. This property does is not used by the Gum tool, but instead exists for runtime implementations (such as FlatRedBall) to decide which type of component to create when an instance of a behavior is requested.
This property may not be used by a particular runtime. For example, at the time of this writing the MonoGame runtime does not use this property.
Behaviors are often used to help with the creation of components which need to have a certain set of states and instances. For example, the Button type in Gum Forms uses a category named ButtonCategory containing multiple states such as Enabled and Disabled.
At runtime, a game may need to create an instance of the Button type without specifying the component associated with the Button forms type. The Default Implementation property can help runtime libraries (such as FlatRedBall) determine which component to create for the Button's visual.
The Button type is a good example of why this property might be needed because the default Forms components include multiple components which implement ButtonBehavior.
To resolve this ambiguity, the ButtonBehavior's Default Implementation is automatically set to Controls/ButtonStandard.
For more information about whether you should set the Default Implementation, refer to the documentation for your particular runtime.
ColoredRectangles are used to display solid color rectangles. It can be used to provide a solid colored background or placeholders for content such as Sprites. ColoredRectangles are also useful for quickly blocking out a UI or learning about Gum's layout with a visual object.
As the name suggests, ColoredRectangles have a Color property which can be modified.
Although Gum includes a standard NineSlice element, the Gum layout system can be used to create a custom NineSlice component. Such a component could be used if additional flexibility beyond what is provided by the standard NineSlice is needed.
As implied by the name, the NineSlice element is composed of nine Sprites. First we'll create the component:
Open Gum
Open or create a new Gum project
Right-click on the Components folder
Select Add Component
Name the Component "CustomNineSlice"
Next, we'll add corner Sprite instances to our CustomNineSlice. We'll be using the alignment tab to position Sprites. The alignment tab provides a quick way to place objects, but the same could be achieved using the following variables individually:
To create the corner Sprites:
Drag+drop a Sprite element onto the CustomNineSlice component
Click the Alignment tab
Anchor the newly-created Sprite to the top-left of its container
Repeat the steps above three more times, creating one Sprite for each of the four corners, anchoring each one to their respective corner
Notice if we resize our CustomNineSlice component, each of the four Sprites remains in its respective corner.
Next we'll add the four Sprites which will sit on the edges of our component:
Drag+drop a Sprite element onto the CustomNineSlice component
Click on the Alignment tab
Dock the newly-created Sprite to the top of its container. Docking sets the width of the sprite to match the width of the component. We'll address this in the next step.
To accommodate for the corner Sprites, we need to adjust the width of the top Sprite. Set the newly-created Sprite's Width
to -128
. Since the Sprite uses a Width Units
of Relative to Parent
, setting the value to -128 makes the Sprite 128 units smaller than its parent. We picked 128 because each of the corner sprites is 64.
Repeat the above steps, but instead setting the dock to create sprites on the left, right, and bottom. adjust width and height values as necessary.
Finall we'll add the center Sprite:
Drag+drop a Sprite element onto the CustomNineSlice component
Click on the alignment tab
Dock the newly-created Sprite to the center of its container.
Set both the newly created Sprite's Width and Height to -128
Unlike the regular NineSlice, changing the texture values requires a considerable amount of variable assignment. To change the CustomNineSlice to use 9 separate textures, the following values must be set:
Each of the Sprite instances must have its SourceFile value set
The edge Sprites will have to have their Width and Height values modified to account for the possible resizing of the corner sprites
The center Sprite will have to have both its Width and Height values modified
If using a sprite sheet, then all of the work above will need to be done plus the texture coordinate values will need to be modified.
Ignored By Parent Size
determines whether the parent of an instance considers the instance when performing its sizing. This value is only used if the parent has a Height Units or Width Units of Relative To Children
. If a parent has a Height Units
or Width Units
of any other value, then this value has no impact on the parent's size.
Introduction
Health bars are common UI elements in games. They are similar to progress bars, so this example could be used to create either. This example explains how to create a health bar component.
First we'll define the component:
Open Gum
Open or create a new Gum project
Right-click on the Components folder
Name the component "HealthBar"
Resize the HealthBar component so it is wider than it is tall. For example, assign Width
to 200
and Height
to 32
.
Next we'll add a background to our HealthBar Component
Drag+drop a ColoredRectangle into the HealthBar
Select the newly-created ColoredRectangleInstance
Select the Alignment tab
Click the Fill Dock button
Change the ColoredRectangleInstance color to black
Now we have a black background in our HealthBar
The HealthBar displays its current health with another rectangle. This second rectangle will be contained inside a container to provide a boundary. To add an inner container:
Drag+drop a Container onto the HealthBar
Select the Alignment tab
Enter a Margin value of 4
Click the Fill Dock button
Now we have a ContainerInstance with the proper margin
Finally we'll add the foreground rectangle which displays the health:
Drag+drop another ColoredRectangle onto the ContainerInstance. Be sure to drop it on ContainerInstance so that the newly-added ColoredRectangle is a child of the container
Click the Alignment tab
Set Margin back to 0
Click the Fill Dock button
Change the following values:
X Units to Pixels from Left
X Origin to Left
Width to Percentage of Container
Width to 100
Now, the Width value can change between 0 and 100 to indicate the health percentage.
Next we'll expose the inner ColoredRectangle's Width
property so it can be assigned per HealthBar instance:
Select the inner ColoredRectangle instance
Right-click on its Width
variable and select Expose Variable
Enter an appropriate name such as "Percentage" and click OK
Now we can add instances of the HealthBar to a screen and control its fill percentage.
Default Child Container specifies which instance should contain children which are added to instances of the current component.
By default this value is blank, which means that children will treat the entire component as their parent. If this value is set, children which are dropped on instances of this component type will use the instance as their parent.
Default Child Container is typically set on containers which are designed to hold children, but which have margins or decoration around the dedicated container instance. Examples include list boxes, tree views, and frames.
Consider a Component named Frame which has two instances: OuterRectangle and InnerRectangle.
This Component is designed to keep all of is children inside the InnerRectangle, so that any child automatically respects the margin specified by InnerRectangle.
To make this kind of relationship the default, the Frame can set its Default Child Container property to InnerRectangle.
Once this value is set, instances which are drag+dropped onto Frame instances will use the InnerRectangle as their parent, as shown in the following animation.
When one instance is drag+dropped onto another instance, the Parent property is set according to the parent's Default Child Container.
Using the example above, the RectangleInstance is dropped on the ContainerTestInstance. Since the ContainerTestInstance is of type Frame, then the Default Child Container is applied on the drop, which results in the RectangleInstance's Parent being set to ContainerTestInstance.InnerRectangle.
The Width Units
variable controls how a unit is horizontally sized, which may be relative to its parent. By default elements uses Absolute
width, where each unit represents 1 pixel of width in absolute terms. When using Absolute
, an object ignores its parents' effective width.
The following shows a child ColoredRectangle with 50
Absolute
Width
:
The following image shows a child ColoredRectangle with -10
Relative to Parent
Width
, so it sizes itself 10 pixels less wide than its parent.
If an instance does not have a parent, then it uses the canvas size when using a Width Units
of Relative to Parent
.
All relationships between parent and children depend only on the direct parent or child. Grandchildren and grandparents are not considered when performing calculations. For more information, see the Parent page.
The following shows a child ColoredRectangle with 100
Percentage of Parent
Width
, which means it has 100% of the effective width of its parent. Note that 100 Percentage of Parent
is the same as 0 Relative to Parent
:
If an object does not have a parent, then the width of the canvas is used.
Ratio of Parent
can be used to fill available space or to share available space with other objects using a ratio. It behaves similar to a Height Units of Ratio of Parent, but operates horizontally rather than vertically.
Ratio of Parent
is usually used with a parent that has its Children Layout
set to Left to Right Stack
or Top to Bottom Stack
. For more information, see the Children Layout page.
The following image shows a child ColoredRectangle with 50
Relative to Children
Width
, which means that it is sized 50 pixels wider than is necessary to contain its children. Since the rectangle has no children, this is the same as having 50
Absolute
Width:
Relative to Children
can be used to size an object based on the position and sizes of a parent's children. The following animation shows a container with 0
Relative to Children
Width
, which means that its effective width is set just large enough to contain its children. Notice that if the children are moved, the parent's effective width adjusts. Both children are considered so the container adjusts its width according to the right-most side of either child:
A non-zero Width
when using Relative to Children
can be used to add additional padding to a parent container. The following animation shows how changing the Width variable can adjust the absolute width relative to children:
Relative to Children
results in effective width dynamically adjusting in response to changes on a container's children. The following animation shows a container with Children Layout
of Left to Right Stack
. Adding additional children expands the container automatically:
A parent container can ignore its children when it determines its absolute width when using a Width Units
of Relative to Children
if any of the following are true:
The child's Ignored By Parent Size
is true.
The child's width depends on its parent's width. This circular dependency is resolved by the parent ignoring this child.
The child is explicitly positioned outside of the parent's bounds
The child's X Units
is Percentage of Parent Width
If a child has its Ignored By Parent Size
set to true, then the parent ignores this child when calculating its own size. For more information, see the Ignored By Parent Size page.
If a child's width depends on the parent, then the child is ignored by the parent. Once the parent has determined its own width, then the child is sized according to the parent. This type of circular dependency is common when adding background visuals to a container.
For example consider a container with two children - BlueRectangle and YellowRectangle - with the following variables:
BlueRectangle X
= Pixels from Left
BlueRectangle Width Units
= Absolute
YellowRectangle Width Units
= Relative to Parent
Only YellowRectangle depends on its parent.
Since BlueRectangle's absolute width value does not depend on the parent, the parent can use BlueRectangle's absolute width when calculating its own absolute width. Since YellowRectangle depends on the parent, the parent ignores the YellowRectangle. Instead, YellowRectangle depends on the parent container's absolute width for calculating its own absolute width. This in effect creates a situation where BlueRectangle affects the width of both its parent and also its YellowRectangle sibling.
A parent does not consider a child if the child is explicitly positioned outside of the parent's bounds. This can happen if the child's X Units
and X
values result in the child being drawn outside of the parent's bounds
If a child has X Units
of Pixels from Left
and its X
value pushes the child out of the left of the parent, then the portion that is outside of the left of the parent is ignored. The BlueRectangle in the following image has an absolute width of 50. Its X
value is -20
, so only 30 pixels are used to determine the parent's effective height.
Similarly, if a child uses an X Units
of Pixels from Right
then the parent does not consider the width of any portion which is outside of its bounds. The following animation shows RedRectangle placed outside of the right of the container's bounds with a X Units
of Pixels from Right
.
Notice that if RedRectangle is moved so that it is inside the bounds, it can affect the absolute width of the parent. As RedRectangle is moved into the bounds, the parent grows to accommodate the desired RedRectangle X
value.
A parent ignores its child if the child uses an X Units
of Percentage of Parent Width
because this also creates a circular dependency (parent width depends on child position, child position depends on parent width).
If a parent sets its Width Units
to Relative to Children
, then it must resize itself to contain its children. Normally the width of the entire parent is determined by the child which needs the most space horizontally. If the parent uses an Auto Grid Horizontal
layout, then the children control the size of the cells rather than the entire parent. Since all cells must be the same size, the child which needs the most amount of space horizontally determines the width of all cells.
For example, the following image shows a four by four grid, each containing one white rectangle. The first rectangle has an Absolute
Width
and Height
of 100
, so each cell is sized to be 100x100. Note that the other rectangles are 50x50.
The largest child determines the cell size for all other children. Therefore, if a child is moved or resized so it outgrows its cell, then the parent width adjusts in response.
Setting a Text instance's Width Units
to Relative to Children
results in the Text object adjusting according to its text contents. In other words if a Text's Width Units
is set to Relative To Children
, then the words in the Text do not wrap.
For example, setting the Width Units
to Relative to Children
and setting the Width
to 0
results in the Text object automatically adjusting its actual width according to the text it contains.
Percentage of Height
adjusts the object's effective width so it remains proportional to the effective height value multiplied by the Width
value (as a percentage). For example, if a Width
value of 200
is entered, then the effective width is 200% (2x) of the height.
The following image shows a child ColoredRectangle with a Width
of 200
Percentage of Height
. In this image, the Height
value is 50
units, so the effective width is 100 units:
Sprites can select a Width Unit
called Percentage of File Width
, which sets the width of the Sprite according to the file that it is displaying. This is the default Width Unit
for Sprites.
The following image shows a child Sprite with 200
Percentage of Source File
Width
, which means it draws two times as wide as its source image:
When using Percentage of Source File
Width, the Sprite's absolute width depends on the Sprite's Texture Width
property.
For more information, see the Sprite Texture Address page.
Sprites can select a Width Unit
called Maintain File Aspect Ratio Width
, which sets the effective width of the Sprite so that its aspect ratio matches its source file multiplied by the Width
value. Usually Maintain File Aspect Ratio Width
is used with a Width
value of 100
so that the Sprite shows is source file at the correct aspect ratio.
Svgs also support using Maintain File Aspect Ratio Width
. For more information on using Svgs see the Skia Standard Elements page.
When this value is used, a Sprite's Height
can be changed resulting in its absolute width also changing.
When using Maintain File Aspect Ratio Width
, the Sprite's effective width depends on the Sprite's Texture Width
property.
Absolute Multiplied by Font Scale
is a value which multiplies the Font Scale
property at runtime with the Width
value. This can be used to create widths which are responsive to font scales for devices which may have variable text sizes.
At the time of this writing, the Gum tool always uses a Font Scale of 1, so this cannot be previewed in the tool. However, when a Gum project is loaded at runtime, the runtime may apply a Font Scale
value such as using the Text size from Windows.
Containers are used to group objects to simply movement, alignment, positioning, and size. Containers are usually invisible, although they can draw their outlines in Gum to help visualize their position and size.
The Children Layout property determines how a container positions its children. The default value is "Regular" which means that children are positioned according to their X Units and Y Units.
Top to Bottom Stack results in the children stacking one on top of another, from top to bottom.
Left to Right Stack results in the children stacking one beside another, from left to right.
Auto Grid Horizontal results in the children being placed in a grid, filling in horizontally first before wrapping to the next row.
Auto Grid Vertical results in the children being placed in a grid, filling in vertically first before wrapping to a new column.
The following shows how to use the ChildrenLayout property to change the default position of a Container's children. The following animation shows the different Children Layouts being set:
Regular layout positions each child independent of every other child. The position of one child does not affect the position other children. This is the default layout for containers.
Top to Bottom Stack results in each child being positioned after its previous sibling vertically. This can be used to create horizontal stacks.
Left to Right Stack results in each child being positioned after its previous sibling horizontally. This can be used to create vertical stacks.
When children stack, each child's X or Y depends on the boundary of its previous sibling. When stacking vertically, the child's Y value begins at the bottom side of the previous item. Similarly, when stacking horizontally, the child's X value begins at the right side of the previous item.
For example, the following image shows a Text object with a Y value of 20. Notice that it is positioned 20 units below the item above it.
This effect is easy to notice when dragging an object inside a stack, as shown in the following animation:
If instances are stacked in a container, the stacking controls the instance values based on the direction of the stack. Containers with a Top to Bottom Stack control the Y value of their children. Similarly, Containers with a Left to Right Stack control the X value of their children. The position value which is not controlled by the stack can be changed freely without any impact on the stacking.
For example, if a container stacks its children using a Top to Bottom Stack, the children in the stack are free to change their X values. The following animation shows how children can be left, center, or right anchored (which changes their X Units and X Origin) without affecting the other children in the stack.
An object will stack only if its position unit values are top or left for vertical or horizontal stacks. For example, if a child is part of a Top to Bottom Stack, it will only stack if its Y Units is set to Pixels from Top. Otherwise it ignores its parents stacking behavior.
In general this behavior can cause unexpected behavior, especially if additional siblings follow the child which is not using the default Pixels from Top or Pixels from Left, so changing this value on the primary stacking direction is not recommended.
Top to Bottom and Left to Right stacks separate their children using the Stack Spacing property. For more information, see the Stack Spacing page.
The position of a child in a stack is determined by the size of the previous item in the stack and the origin of the child. In most cases children which are stacked should use a Left X Origin if the parent uses a Left To Right Stack and should use a Top Y Origin if the parent uses a Top To Bottom Stack.
Consider a container with a blue rectangle which stacks horizontally. The blue occupies some space according to its absolute width. The next instance after the blue rectangle is placed relative to the right-side of the blue rectangle.
For example, if a red rectangle is added to the container, the stack may create a layout similar to the following image:
Keep in mind that the stack simply states the position of the next item. Each item can freely adjust its X Origin (or Y Origin in a Top to Bottom Stack). If the red rectangle's X Origin is changed to Center, the red rectangle overlaps the blue rectangle.
If the red rectangle's X Origin is changed to Right, then its right side will align with the right side of the blue rectangle, resulting in the red overlapping the blue completely. In this case the stacking is essentially cancelled out by the X Origin.
This overlapping may not be desirable, so keep this in mind when changing a stacked child's origin.
The Wraps Children property controls how stacking behaves beyond boundaries. For more information, see the Wraps Children page.
Children of a container which uses the TopToBottomStack or LeftToWriteStack will be ordered according to their order in the tree view on the left. By default this is the order in which the children are added to a parent container.
Children can be reordered using the right-click menu on an instance.
Alternatively, children order can be changed by clicking on the item in the tree view, holding down the ALT key, then pressing the up or down arrows.
For more information on ordering, see the Order page.
Auto Grid Horizontal and Auto Grid Vertical layouts result in each child of the container being placed in its own cell. All position and size values are relative to the entire cell, so children can expand to fill their cell or be positioned according to any side or corner.
The following shows a container with an Auto Grid Horizontal and Vertical Cells of 2, resulting in a 2x2 grid. As children are added to the container through copy/paste, each child is placed in its own cell.
The number of cells is controlled by the Auto Grid Horizontal Cells and Auto Grid Vertical Cells. Increasing the number of cells results in the rows or columns adjusting automatically.
Each child occupies one cell, and the order of the children controls the order of the placement in grids. The first child occupies the top-left row. If using Auto Grid Horizontal, each child is placed to the right of its preceding sibling, wrapping to the next line when reaching the end of a row. If using Auto Grid Vertical, each child is placed below its preceding sibling, wrapping to the next column when reaching the end of a column.
Children can be reordered by using the alt+arrow key in the tree view, resulting in reordering just like when using a stacking Children Layout.
Children treat their particular cell in the grid as their parent, so any sizes or positions will be based on their parent cell. In other words, if a child's WidthUnits is set to RelativeToContainer, the container in this case is the cell, not the entire Container instance.
If additional children are added beyond the number of cells in a grid, additional children will spill over the bounds of the grid. The following animation shows a 3x3 grid using Auto Grid Horizontal. As more children are added, additional rows are added below the bounds of the grid.
When using Auto Grid Horizontal, the number of columns is fixed, but additional rows can be added beyond the bounds of the container.
When using Auto Grid Vertical, the number of rows is fixed, but additional columns can be added beyond the bounds of the container.
Contained Type enables code generation and Gum runtimes (such as FlatRedBall) to create strongly-typed containers.
Currently the Contained Type variable does not have any affect on objects in the Gum tool and it exists only to support strongly-typed runtimes. This may change in future versions of the Gum tool.
Some Gum components or Containers may exist to hold a list of a particular type of item. For example, consider a game which includes a row of hearts to show the player's current health.
In this particular case, the hearts can be filled or empty to show the current and max health, but the max health can also be increased. If the max health increases, then a new heart instance is added to the container at runtime.
Since this container should only ever contain instances of a Heart component, then the container's Contained Type can be set to Heart.
In this example, FlatRedBall respects the Contained Type variable and generates a generic list.
As mentioned above, the implementation of this variable depends on the runtime you are using. If you are using a runtime which does not implement this feature and you would like to have it added, please create a GitHub issue or make a request in Discord.
The Wraps Children property controls whether children wrap or stack beyond their container's boundaries when the container's Children Layout is set to Top to Bottom Stack or Left to Right Stack.
If a parent has Wraps children set to true, the wrapping adjusts in response to resizing the parent.
Similarly, resizing a child may result in the stacking changing.
The row height in a Left to Right Stack is determined by the largest child in the row.
Similarly, column width in a Top to bottom Stack is determined by the largest child in the column.
The Custom Frame Texture Coordinate Width property allows a NineSlice to customize the number of pixels used on the source texture when defining its outer frame. This allows for fine control over which parts of a NineSlice stretch and which parts are used as the corners and edges.
By default this value is null, which means the NineSlice automatically dedicates 1/3 of the texture for the edges.
If the Custom Frame Texture Coordinate Width value is changed, then the source texture applies a fixed pixel size to the borders. For example, using the image above, the frame can be changed to 3 so that only the black and white pixels are part of the border.
The Y Origin variable controls the point which an object is positioned by. By default the Y Origin is Top. The Y Origin is shown visually as a white "X" in the editor.
The following image shows a ColoredRectangle with its Y Origin set to Top:
The following image shows a ColoredRectangle with its Y Origin set to Center:
The following image shows a ColoredRectangle with its Y Origin set to Bottom:
The following shows a Text with its Y Origin set to Baseline:
Baseline refers to the bottom of the text for letters without descenders. For more information see the Wikipedia Baseline page.
Baseline is often used to align fonts of different sizes. The following image shows two Text instances with different font sizes. Both are positioned by their baseline so their bottoms align properly (ignoring descenders, such as on the letter p and the comma).
By contrast, the following image shows the same Text instances using bottom alignment.
Behaviors can define requirements which are reusable across multiple components to standardize instance names and behaviors. If a component uses a behavior, then the behavior is forced to include categories and instances according to the behavior definition.
Behaviors are used to define requirements for components, to simplify the creation of new components, and to reduce the chances of spelling and implementation mistakes.
C# programmers may find the concept of behaviors to be similar to interfaces in code. Behaviors define requirements for components, but they give components the flexibility to implement these requirements, just like interfaces define required properties and methods which classes can implement.
Behaviors are used to standardize state, category, and instance names. The most common usage of behaviors is with Gum Forms. Of course, behaviors can also be used to standardize names in your project for components which are not intended to be with Gum Forms.
To add a behavior:
Right-click on the Behaviors folder
Select Add Behavior
Enter the new behavior name. Often time the word Behavior is added at the end of the name, such as ButtonBehavior
New behaviors appear in the Project tab.
Once a behavior is created, it can be given categories, states, and instances. Components which use this behavior are required to have matching categories and states.
The process of adding and removing states to behaviors is the same as adding and removing states in other elements. For more information, see the States page.
For example, the ButtonBehavior may have the following:
ButtonCategory (Category)
Enabled (State)
Disabled (State)
Focused (State)
Pushed (State)
A behavior can have as many categories and states as needed.
Once a behavior is added, it can be used in a component. To add a behavior to a component, drag+drop the behavior onto the component in the tree view.
Behaviors can also be added and removed on the component's Behaviors tab:
Select a component which should use the behavior
Click the Behaviors tab
Click the Edit button
Check the desired behaviors - a component may use multiple behaviors
Click OK
Notice that once a behavior is added to a component, the component automatically creates the matching categories and states.
If the behavior is selected in the Behaviors tab, the required states and categories are highlighted in the States tab.
These categories cannot be removed as long as the component uses the behavior.
As mentioned above, if a component uses a behavior, then the component is required to include all of the states and categories defined by the behavior. If a behavior is added to a component, then all states and categories in the behavior are automatically added to the component. Keep in mind that newly-added states do not automatically assign any values. The behavior only requires that the states exist but it does not decide which variables are assigned by the states. These required states can even be left to their default so they have no affect on the component.
Required states and categories cannot be removed or renamed. Required states cannot be moved to different categories.
If a new category or state is added to a behavior, all components which use the behavior also have the new category or state added.
If a state or category is removed from a behavior, Gum does not remove the state or category from components which implement the behavior. Behaviors only define what is required, but they do not prevent components from defining additional states and categories. Also, the states on components may still be needed even if the behavior is removed. Therefore, if you remove any states or categories from a behavior, you may need to manually remove the same states and categories from components which use the behavior if these are no longer needed.
Behaviors can include instances, resulting in required instances existing in components which use the behavior. Instances in behaviors only include two properties:
Name
Base Type
Instances in behaviors only require that instances in components have these two matching properties. All other properties can be set to any value.
To add an instance to a behavior, drag+drop a standard element or component onto the behavior in the Project tab.
An instance can have its Name changed, Base Type changed, or removed.
If a component is missing a behavior then the Error window provides information about the missing requirement.
At this time Gum does not automatically add required instances to components which need them. This may change in future versions of Gum. For now, instances must be manually added to resolve errors.
NineSlice is a standard component which can be used to create visual objects which can stretch to any size without creating distortion on the source image. For example, consider the following image:
This image could be used to create nine slices of various sizes without any distortion:
The NineSlice achieves this effect by splitting the texture into nine pieces, and scales each one differently to prevent distortion. Highlighting a nine slice shows how it is split:
This is achieved by splitting the texture into 1/3 sections wide and tall. The following image shows how the original image will be split:
The simplest way to assign a texture to a NineSlice is to use a single file. Setting the SourceFile to a single PNG will result in the NineSlice using that one texture, where each section of the NineSlice displays 1/3 of the width of the file and 1/3 of the height of the file.
A NineSlice's Texture Address property can be used to change the portion of the source texture that it uses. More info can be found in the Texture Address subpage.
Alternatively, nine files can be used to specify each section of the NineSlice independently. To use nine individual files, each file must be given a specific suffix.
The following suffixes can be added to create nine slice graphics. For example, assuming your NineSlice image is called "Image" and you are using the .png file format:
Image_BottomCenter.png
Image_BottomLeft.png
Image_BottomRight.png
Image_Center.png
Image_Left.png
Image_Right.png
Image_TopCenter.png
Image_TopLeft.png
Image_TopRight.png
The Texture Address variable can be used to define the area that the NineSlice displays. By default the Texture Address is set to Entire Texture which means the NineSlice will display the entire source file (split up among the nine pieces).
NineSlice only supports Entire Texture and Custom for the Texture Address value. It does not support Dimension Based, which is only available on the Sprite element.
The following screenshot shows an entire texture being used for a NineSlice.
The entire texture is split up into 3 sections horizontally and 3 sections vertically, matching up the texture coordinates used to display the NineSlice's 9 sections.
The Custom value allows specifying a custom set of coordinates for the Nine Slice. Custom is most often used when an image is part of a sprite sheet. The following example uses this image:
The NineSlice uses the following variables:
Texture Address = Custom
Texture Top = 0
Texture Left = 0
Texture Height = 40
Texture Width = 40
These values result in the the following NineSlice:
The Texture Left variable controls the left pixel of the source rectangle used to draw the NineSlice. Texture Left is only available if the NineSlice uses a Texture Address of Custom or Dimension Based.
The following image shows a NineSlice with a Texture Left value of 96.
Texture Left controls the left side of the region that the NineSlice displays on its source file. In this case, the left-edge of the source rectangle is 96 pixels from the left edge of the entire file.
Points are an ordered set of X,Y values defining the shape of the polygon. All points are relative to the Polygon's position. Typically the last point is the same as the first point creating a closed polygon.
By default polygons have four sides. Since the first and last point is repeated, a four-sided polygon has five points.
Each point is relative to the polygon's X and Y (position). Points use pixel coordinates. The following image shows a polygon with the following points:
-32, -32
32, -32
32, 32
32, -32
-32, -32 (repeat of first point)
Notice that the image above has points which appear above and to the left of the polygon's origin.
The easiest way to add points is by selecting a Polygon, then clicking on the + icon that appears in the center of the line where you would like to add a point. The following animation shows how to add points to a square to create an octagon:
Points can be moved by clicking on them and dragging them in the editor. Note that points can be positioned anywhere, even if lines cross or if a polygon is concave.
A point can be removed by clicking on it and pressing the delete key.
Points can also be edited manually in the Screen or Component which contains the Polygon instance. You can open the file in a text editor to see a list of points.
For example, consider the following polygon:
The points for this polygon defined in the MainMenu XML file might look like this:
These points can be changed in the XML file. If the file is changed then Gum automatically reloads this file.
Remember that the first and last points should have the same values if you want your polygon to be closed. You can make edits in the XML file to separate the start and end if you would like to draw a segmented line rather than a closed polygon.
The Texture Top variable controls the top pixel of the source rectangle used to draw the NineSlice. Texture Top is only available if the NineSlice uses a Texture Address of Custom or Dimension Based.
The following image shows a NineSlice with a Texture Top value of 48.
Texture Top controls the top side of the region that the NineSlice displays on its source file. In this case, the top-edge of the source rectangle is 48 pixels from the top edge of the entire file.
The Stack Spacing variable controls the additional padding between children when a container uses a Children Layout of either Top to Bottom Stack or Left to Right Stack. Stack Spacing serves as an alternative to adjusting the position of each item in a stack.
A larger Stack Spacing value increases the spacing between each child. By default Stack Spacing is set to 0 which means that no spacing is added between items in a stack.
Changing the stack spacing adds gaps between each child as shown in the following animation.
Stack Spacing can also be a negative value resulting in overlapping children. The items in the following animation are partially transparent to show the overlap.
Stack Spacing can be used for either Top to Bottom or Left to Right Stacking.
Stack Spacing can be used on container instances which stack and wrap their children. As stack spacing increases, the amount of space allocated to each object also increases, resulting in wrapping occurring earlier.
If wrapping occurs, then stack spacing applies spacing between rows and columns as shown the following animation:
Circle - circle outline. These are usually not used for UI, but can be used if you are defining collision in your Gum objects for a game.
ColoredRectangle - filled-in rectangle. These are often used for solid-colored backgrounds and frames.
Container - invisible object used to contain other objects. These are used to provide margins, change layouts (such as vertical vs horizontal stacking), and to organize your UI.
NineSlice - visual object which uses nine sprites to create a resizable object from a source PNG (or portion of a PNG). The corner sprites (4) are not resized. The top, bottom, left, and right sprites are stretched on one axis. The middle sprite stretches both horizontally and vertically. These are used to create resizable frames.
Polygon - polygon outline which can have any number of points. These are usually not used for UI, but can be used if you are defining collision in your Gum objects for a game.
Rectangle - rectangle outline. These can be used for single-line frames or if you are defining collision in your Gum objects for a game.
Sprite - a visual object which displays a source PNG (or a portion of a PNG). These are used for icons, backgrounds, and other visual objects which are usually not resized dynamically.
Text - a visual object which can display characters. These are used for any situation where text needs to be displayed such as labels and paragraphs.
Whenever you have a non-Default state selected, Gum displays a label telling you which state you are editing.
Now the Sprites stretch and adjust whenever the CustomNineSlice is resized.
Skia standard elements are a collection of elements which use SkiaSharp for rendering. Skia standard elements provide additional types of visuals supported by Gum, but not all runtimes support Skia standard elements.
Skia adds advanced vector graphics support for shapes such as Arc, ColoredCircle, and RoundedRectangle. Skia also adds support for vector file formats such as SVG and Lottie.
At the time of this writing, Skia standard elements are only supported in FlatRedBall projects. Future versions of MonoGame Gum will add support for Skia runtime objects. If your project needs Skia, please make a request in Discord or on GitHub.
Skia standard elements must be explicitly added to gum projects. To add Skia standard elements Select Plugins -> Add Skia Standard Elements.
After clicking this option, Gum adds new standard elements.
Once these Skia standard elements are added, they can be added to Screens and Components just like any other standard element.
The Use Gradient property controls whether a Skia Standard Element uses gradient values if true or a solid color if false.
By default this value is false.
If this value is set to true, then additional properties appear for controlling the gradient.
Gradients create a smooth interpolation of color from the first set of values (Red1, Green1, Blue1) to the second set of values (Red2, Green2, Blue2).
Changing these values adjusts the gradient start and end colors.
The gradient values appear at their respective values at the points specified by Gradient X1, Gradient Y1, Gradient X2, and Gradient Y2. For example the gradient points could be visualized as shown in the following image:
Changing the Gradient X or Y values changes the start and end points for the gradient.
Gradient values use Units similar to X Units and Y Units. By default, gradient values are relative to the top-left of the element. Since the gradient values are not affected by size, changing the size of the element does not affect the gradient.
The gradient X and Y units can be changed. Each value can be set independently. For example, the X2 and Y2 units can be adjusted to be relative to the bottom-right corner of the instance. The following shows a RoundedRectangle with the Gradient X2 and Y2 values 100 pixels up and to the left of the bottom-right corner. If the RoundedRectangle is resized, then the gradient adjusts in response.
Gradient X and Y values can exist outside of the visual space of the instance, and even outside of its bounds. The following image shows an Arc with a gradient which is defined below the visual part of the arc. Notice that the Gradient Y values are both 0 PixelsFromBottom.
Gradient Type controls whether the gradient is linear or radial. Radial gradients place the center of the radial gradient at X1,Y1 and the edge of the radial gradient at X2, Y2.
Has Dropshadow controls whether a dropshadow is drawn below an element. By default this value is false.
The following image shows two RoundedRectangles. The left with Has Dropshadow unchecked, the right with Has Dropshadow checked.
Note that if an instance has a dropshadow, the dropshadow renders outside of the bounds of the instance.
Dropshadows draw as part of the object, so if multiple objects stack, their dropshadows also stack.
Dropshadow Offset X and Y control the position of the dropshadow relative to the main body of the instance. By default this value is 3 pixels below (Dropshadow Offset Y of positive 3).
This value can be changed to offset the dropshadow in any direction increasing a sense of height for the element.
Dropshadow Blur X and Y control how much to blur the dropshadow on the X and Y axes, respectively. A value of 0 creates a sharp shadow, while a larger value increases blur. Note that the X and Y values can be adjusted independently.
Dropshadow blur values roughly measure the number of pixels that it takes to interpolate the edge of a shadow from its full color to fully transparent. This value is not exact due to antialiasing.
Dropshadow Alpha controls the transparency of a dropshadow. A fully-opaque dropshadow has an alpha of 255. This value can be modified to decrease or increase the dropshadow's opacity.
Dropshadow Red, Green, and Blue can be used to adjust the dropshadow color. Usually dropshadows are pure black with their transparency adjusted by Dropshadow Alpha, but they can also include other colors if needed.
Is Filled controls whether a shape is filled in or if it is drawn using stroke - another word for outline. By default this is true, but it can be unchecked to make a shape draw its outline.
Stroke Width controls the thickness of the stroke (outline). Increasing the value makes the stroke thicker.
If a Skia standard element has its Is Filled unchecked, this affects the rendering of gradients and dropshadows.
Gradients only fill the solid parts of a shape, so if a shape has Is Filled set to false, the hollow center of the shape does not show gradient color.
Dropshadows respect the opaque part of the shape, so changing Is Filled also affects the dropshadow.
Start Angle defines the angle of the starting point of the arc. This value is measured in degrees, with a value of 0 pointing to the right. The value increases counterclockwise. the Start Angle and Sweep Angle values combine to determine the range of angles covered by the Arc.
The following image shows the an Arc with a Start Angle of 0. The red lines and text are not part of the arc and are added to the screen shot to show the location of the Start Angle.
Changing the Start Angle moves one side of the arc. The arc appears to rotate if the Start Angle is changed gradually.
Start Angle defines the starting point of the arc. A value of 270 degrees and a value of -90 place the starting point of the arc in the same location. Values larger than 360 result in the value looping. These values, although normally not needed, can be used to create spinning animatoins.
Arcs are curved lines with variable thickness. Arcs can also be used to draw wedges if the line thickness is large enough.
Arcs draw inside their bounds, with the edge of the arc touching the bounding rectangle. The thickness of the arc remains consisntent regardless of the bound width and height.
The following shows an arc with a Sweep Angle of 270 degrees, being resized in the Editor tab.
ColoredCircle are round shapes which can be filled in or drawn as an outline. Unlike the non-Skia Circle element, ColoredCircles can be filled in and provide more options for customizing their appearance.
ColoredCircles support Skia properties such as Has Dropshadow, Is Filled, and Use Gradient. For more information and examples, see the Skia Standard Element General Properties pages.
Sweep Angle defines the angle that the arc covers. This is a signed value, with positive values going counterclockwise.
The following shows an arc with a positive Sweep Angle of 135 degrees.
Changing the Sweep Angle changes the length of the arc. If the value is negative, then the Sweep Angle increases the size clockwise.
A sweep angle of 360 creates an arc that extends to a full circle. Values greater than 360 appear the same as if Sweep Angle is set to 360.
LottieAnimation instances can render animations in the Lottie format. Lottie files are animated files, usually with vector art, which serve as an alternative to gifs. Since they are often vector art, Lottie files can be resized without pixelation.
Lottie files can be downloaded from various sites or created in application such as Adobe After Effects. If you are interested in testing out Lottie animations, you may want to check lottiefiles.com for sample Lottie files.
The following shows a Lottie animation playing in Gum. Source file: https://lottiefiles.com/free-animation/city-skyline-HFnJYQZLPP
The Source File variable controls the lottie animation displayed. This value can be set and changed just like source files on other elements such as a .png on a Sprite.
Width and Height values can be set on a Lottie file just like any other Gum element. Unlike rasterized objects such as Sprites, LottieAnimations use Vector art so they can be resized and still retain crisp edges and details.
LottieAnimations are still rasterized in Gum, so they display pixels when the view is zoomed in, especially if the LottieAnimation has a small Width or Height.
RoundedRectangle is similar to a ColoredRectangle with the added functionality of supporting rounded corners.
RoundedRectangles also support Skia properties such as Has Dropshadow, Is Filled, and Use Gradient. For more information and examples, see the Skia Standard Element General Properties pages.
The Canvas element creates an instance of a SKCanvas which can be accessed in code to perform custom rendering. The contents of the Canvas cannot be modified in Gum. Since it is a Gum object, it does provide all of the variables for positioning, sizing but the rendering must be performed in custom code.
Since the Canvas cannot perform any rendering in Gum, it appears as an empty container.
Thickness controls the width of the arc line in pixels. This value can be increased to make the line arc thicker.
Thickness can be increased to create a wedge.
Note that Thickness can be increased to any value including values larger than the radius of the arc. Large values can result in the arc rendering past its center point creating a bowtie shape.
Other undesirable rendering effects can happen with large thicknesses when working with arcs which have one size (width or height) larger than the other, as shown in the following image:
The Blend variable controls how the selected instance combines its colors with whatever is drawn before. The final appearance of a Sprite or NineSlice depends on its Blend, Alpha, Source File, and Color values.
Normal Blend is the default value. When an instance uses Normal Blend, it interpolates its color with whatever it draws on top of using its Alpha value as a weight.
If a Normal Blend Sprite has an Alpha of 255, then the Sprite completely replaces whatever it is drawn on top of.
If a Sprite has an alpha of 128 (roughly half of 255), then it averages its color with whatever it is drawn on top of.
A Sprite with 25 alpha (roughly 10%) will blend with whatever it is drawn on top of, but its color is given a weight of roughly 10%.
The examples above use the Alpha value to apply transparency. Note that if the source file (.png) has transparency as part of the file, the same effect applies.
Additive Blend results in the color of a Sprite being added to whatever it is drawn on top of. This typically results in the Sprite or NineSlice making things brighter. Additive Blend can be used to simulate a light.
Since Additive Blend results in a modification of what is under instead of a replacement, an Additive Blend Sprite or NineSlice typically appear transparent even when Alpha 255.
As alpha is reduced, the brightening effect is reduced. A Sprite or NineSlice with an alpha of 128 only applies roughly half as much of a brightening effect.
A Sprite or NineSlice with an alpha of 25 applies a slight brightening effect.
Stacking multiple Sprites or NineSlices with an Additive Blend results in the brightening effect stacking as well.
Replace blend results in the Sprite or NineSlice completely replacing whatever it is drawn on top of regardless of Alpha or transparency in the source file.
A Sprite with no transparency in its source file drawn at 255 looks the same whether it uses Replace Blend or Normal Blend.
Changing the Alpha on a Sprite or NineSlice with Replace Blend does not affect how it is drawn - it is always drawn at full opacity.
Replace Blend results in a Sprite or NineSlice being fully opaque even if its source file has transparency. The following image shows two Sprites displaying the same image.
Svgs can display .svg files. Since these files are vector art, they can be resized without pixelation.
The following is an Svg instance displaying the FlatRedBall logo. Source SVG: https://github.com/flatredball/FlatRedBallMedia/blob/master/FlatRedBall%20Logos/frb-logo-main.svg
The Source File variable controls the lottie animation displayed. This value can be set and changed just like source files on other elements such as a .png on a Sprite.
Width and Height values can be set on an Svg file just any other Gum element. Unlike rasterized objects such as Sprites, Svgs use Vector art so they can be resized and still retain crisp edges and details.
Svgs are still rasterized in Gum, so they display pixels when the view is zoomed in, especially if the Svg has a small Width or Height.
Svgs support the Maintain File Aspect Ratio Width and Maintain File Aspect Ratio Height units. For more information, see the Width Units and Height Units page.
The Source File property determines the file that is used by the Sprite. Sprite Source Files support the following formats:
.png files
.achx files (AnimationChains)
Images from URLs
If a Sprite has an empty Source File or if it references a missing file, then the missing file texture is displayed.
Source File can be set by typing a value or using the ... button to browser for a file.
All files are added as paths relative to the .gumx project.
If a file is referenced outside of the .gumx folder, then Gum asks if you would like to copy the file or reference it outside of the current directory. Usually files should be copied to the project folder to keep the entire Gum proejct portable.
Gum natively supports referencing Animation Chain XML files (.achx) which are created by the FlatRedBall AnimationEditor. For more information on creating .achx files, see the FlatRedBall AnimationEditor page.
Once you have created an .achx file, you can reference it the same as a .png by entering its name or selecting it with the ... button.
When referencing an .achx file, be sure to also check the Animate checkbox and to select the Current Chain Name.
.achx files are XML files which reference one or more other PNG files. If you are moving an .achx file be sure to also move the referenced PNG files.
Gum Sprites can also reference URLs. Gum can display images from URLs with standard file extensions such as .png and .jpg
Sprites can also reference images without extensions, such as urls from https://picsum.photos/
The texture address property controls the texture address behavior of a sprite. Specifically it can control whether texture addresses variables are available, and how texture coordinates and sprite size are related.
If the texture address property is set to EntireTexture then the sprite draws its full image. The sprite does not repeat or render only part of the texture. This renders the entire image.
If the texture address property is set to Custom then the top, bottom, left, and right properties can be independently set. This allows a sprite to only render a portion of its source texture.
Typically a Texture Address of Custom is used in combination with a Width Units of Percent of File Width and a Height Units of Percent of File Height. In this case, the size of the sprite depends on the texture coordinates.
When using Custom Texture Address, wrapping is possible. For more information see the Wrap page.
If the Texture Address property is set to DimensionsBased then the texture coordinates adjusts internally according to the width and the height of the Sprite. In other words, making the sprite larger or smaller does not stretch the image that it is rendering. Instead the image is be clipped, or clamped/wrapped according to the Wrap property.
When the Texture Address is set to DimensionsBased, then the Texture Width and Texture Height values are replaced by Texture Width Scale and Texture Height Scale. In this mode, the Texture Width and Texture Height values are calculated by multiplying the absolute size of the Sprite by its respective scale values.
When using DimensionsBased Texture Address, wrapping is possible. For more information see the Wrap page.
If a Sprite uses a Width Units of Percentage of File Width or a Height Units of Percentage of File Height, then the Width and Height values represent the size of the sprite relative to the entire source file.
For example, if a Sprite is displaying a source PNG file with a width of 130 pixels and its Width is 300, then the absolute width of the Sprite is 390 (130 * 300%). If Wrap is checked, then this indicates the number of times that the image repeats on the Sprite.
The Texture Width Scale and Texture Height Scale values determine the size of the texture on the Sprite when using DimensionsBased Texture Address. By default this value is 1, which means that the source image displays at its native size.
Increasing this value results in the image displaying larger. For example setting a value of 2 results in the displayed image being twice as large. Scale values for width and height can be set independently.
Since a larger value results in the image appearing larger, this means that mathematically a larger scale value results in smaller Texture Width and Texture Height value.
Categories can be used to organize similar states into one group (such as a button's Pressed and Unpressed states).
A category can contain one or more states. States within a category have special behavior:
If one state in a category explicitly sets a variable (such as X), then all other states in that category will also explicitly set the variable.
Each category can be set individually on an instance of a component or standard element. In other words, if a component has two categories, each category can be assigned to a state within that category independently.
Normally, when a new state is created, all variables are explicitly unset. The value displayed in the properties window will be the value inherited from the default state.
For example, the following image shows a component with a state called State1 with no variables explicitly assigned. Notice all values are green:
We can see the same behavior on a categorized state. The following image shows the categorized LeftSide state with all inherited values:
As mentioned in the introduction, if a variable is explicitly set on one state in a category, then all other states in that category will that same variable set to its default.
For example, if we set the X variable in the LeftSide state, the X variable in the RightSide state will become explicitly set (black instead of green).
Once the X variable is set on one state in a category, all other states in the same category will automatically have this value set - even new states:
Variables can be removed from states, but this removal must be done at the category level rather than at the individual state. Doing so will remove all variables from all states within a category. To remove a variable in all states in a category:
Select the category itself (not the state)
Click the "X" button next to the variable
Confirm that you would like to remove the variable. Warning: this will remove the variable from all contained states.
This will remove the assignment of the variable from all states in the category.
Introduction
The Wrap value controls whether the sprite wraps its image when rendering portions beyond the right and bottom image bounds. If this value is true then wrapping occurs. Otherwise, areas beyond the texture extend the last pixel - also known as "clamping" the value.
The Wrap variable applies when dealing with a Texture Address of Custom or DimensionsBased. Wrapping is not available when using a Texture Address value of Entire Texture.
If Texture Address is set to Custom then wrapping is available. All examples in the Custom Texture Address section use the following values:
Width = 100
Width Units = Percentage of File Width
Height = 100
Height Units = Percentage of File Height
For more information, see the Width Unit and Height Unit pages.
Toggling wrapping adjusts whether the Sprite wraps or clamps the area defined by the Texture Left, Texture Top, Texture Width, and Texture Height values.
A texture is wrapped if its Texture Right or Texture Bottom values are set to be larger than the source texture. For example, the following image shows a Sprite which is using an image that is 200x200. Its Texture Width is set to 500 and Texture Height is set to 300 so the sprite displays wrapping.
If the Texture Width or Texture Height values are adjusted, then the Sprite's wrapping also adjusts.
If Wrap is set to true, then wrapping happens for any area to the right or bottom of the bounds of the source. The following shows the bounds of a sprite moved in the Texture Coordinate tab resulting in the area that is being displayed wrapping and repeating.
If a Sprite's Texture Left or Texture Top are set to less than 0 then the Sprite clamps this area. This may change to wrap in future versions of Gum so this behavior should not be relied upon.
If a Sprite sets DimensionsBased for its Texture Address, then its source file can wrap if its dimensions are large enough to result in the texture width or texture height set to a value larger than the source dimensions.
All examples in the DimensionsBased Texture Address section use the following values:
Width Units = Absolute
Height Units = Absolute
Toggling wrapping adjusts whether the Sprite wraps or clamps the area defined by the Texture Left, Texture Top, and its size.
If a Sprite's width or height are adjusted, this results in its texture coordinate values also being modified. If Wrap is true then areas outside of the source file wrap.
Wrapping can also be affected by changing the Texture Width Scale or Texture Height Scale. Smaller values result in image being drawn smaller, making it wrap more.
The text object can be used to display written information. The text object supports:
Horizontal and Vertical alignment
Text wrapping
Fonts from the installed font library on your machine
Custom fonts using Bitmap Font Generator: http://www.angelcode.com/products/bmfont/
Scaling independent of source font
BBCode-style inline formatting
Texts wrap their contained words based on their dimensions. Whether a text wraps ultimately depends on whether the Text's Width Units
is Relative To Children
.
The following animation shows text wrapping on a text which is using an Absolute
Width Units
.
The Color value controls a Text object's color. The Color value is created by combining the Red, Green, and Blue values.
The Color value can be changed through the color picker, or by changing the individual Red, Green, and Blue color values.
For default Text objects, the Color value modifies the displayed Text color. Gum creates .fnt and .png files where the color is white. If the .png includes any colors that are not white, then the resulting color is produced by multiplying the color value with each pixel. Therefore, if a Font is outlined, then the black pixels remain black.
The Color value is used to perform a multiply color operation on the sprite. Color values can be used to darken or tint a grayscale texture. By default Sprites us a white color, which means the original texture will display unmodified.
The following images show the color values as applied to a multi-color sprite.
Red: 255 Green: 255 Blue: 255
Red: 255 Green: 0 Blue: 0
Red: 0 Green: 255 Blue: 0
Red: 0 Green: 0 Blue: 255
Red: 128 Green: 128 Blue: 128
Red: 0 Green: 0 Blue: 0
The font scale property allows you to zoom a font in or out, effectively making the text larger or smaller. Unlike using the font size property, font scale will not re-create the font (when using standard fonts). Font scale is also necessary for resizing custom fonts.
By default Text objects Font Scale value of 1.
Font scale can be increased, but doing so can make fonts pixellated. For example, setting the Font Scale value to 5 makes each pixel on the font 5x as large, resulting in a pixellated text object.
Similarly, FontScale can be set to a value smaller than 1, resulting in a shrunk font.
The Green value controls the color of the Text object. The Green value has a range of 0 - 255. The Green value combines with the Blue and Red values to create the final color.
For more information on working with color, see the .
The Font variable sets the font family used by the text.
This dropdown appears only if Use Custom Font is set to false.
The Font dropdown has access to any font which is installed locally.
To use a font in Gum, download the font and install it by double-clicking or right-clicking on the font.
Gum performs rendering using rasterized fonts. In other words, it renders using pre-made .png files which contain all of the characters in a font.
You can view the Font Cache in your project by selecting Content -> View Font Cache.
This folder contains all font files used by your project.
Note that each font has three files:
bmfc - Bitmap Font Generator configuration file. This can be opened in Bitmap Font Generator to see the settings that have been used to export the other files
fnt - Bitmap Font Generator font file. This is a text file indicating the location of each character in the matching png files. It also includes kerning pairs.
png - This is the image file containing the letters for the font. The font may contain multiple image files if the character set or font size are large enough.
Each PNG can be opened in an image editor to view the packed characters. For example, the following shows the Arial 24 font. The blue background has been added manually to make the white characters visible:
Fonts are generated as needed by Gum. This happens whenever a property changes on a Text object requiring a new font. Gum only re-generates fonts if a matching font doesn't already exist. The following animation shows new fonts being generated as a Text's Font Size is changed.
Fonts are generated in response to any of the following properties changing:
Font
Windows Machines typicall have dozens of fonts installed automatically. You may be working on a project which needs custom fonts. These fonts can be obtained on many websites including https://www.dafont.com/ and https://fonts.google.com/.
Once a font has been installed, you must restart Gum for the font to be available in the Font dropdown.
The Blue value controls the color of the Text object. The Blue value has a range of 0 - 255. The Blue value combines with the Red and Green values to create the final color.
For more information on working with color, see the .
Font Size controls how large a font appears on screen. Each font size and Font combination creates its own rasterized font, so using a lot of different font sizes will increase the amount of texture memory your game needs.
The Font Size property can be set in Gum to make a text object's font larger or smaller. For example, the following shows a Text object with a font size of 18:
Changing the font size will increase the size of the Text object. For example, here is the same Text object with a Font Size of 36:
The first time a Font and Font Size combination are referenced, Gum creates a file in the FontCache folder. You may notice a small pause in Gum when setting Font and Font Size combinations for the first time as the file is created, but subsequent changes will be fast.
The FontCache folder is located in the following location:
/FontCache/
Games which are using fonts that are intentionally pixelated should avoid setting Font Size in-between the intended font size multiples for the given font. These sizes depend on the specific font used, and may require some trial and error.
For example, consider the font Press Start 2P which can be installed from https://fonts.google.com/specimen/Press+Start+2P
Font Size can be set to any value, but this font only looks good if Font Size is set to 8.
The rendering artifacts are more obvious when zooming in, as shown in the following image:
Of course, we could also set the Font Size to 16, but this is unnecessary. Since text instances using pixelated fonts usually have Use Font Smoothing set to false, then the Text can use its Font Scale to adjust its size.
This value controls the number of letters that the Text object will show. This value is used when displaying the text, but is not used when calculating the Text size or line wrapping.
If the value is <NULL>, then there is no maximum - all letters are displayed.
Max Letters To Show limits the number of characters (including spaces). By default this value is <NULL>, which means a Text object will display its full string. Setting this value will adjust the display of the text, but it will not impact any layout values.
For example, by default a Text object displays all of its letters. Note that the Width is fixed, and the Height depends on the contained text - the Height is automatically set on the Text object according to the contents of the text.
Setting Max Letters To Show value to 30 restricts the Text object to displaying its first 30 characters, but the size and line wrapping do not change.
Max Letters To Show applies after all layout and text positioning has been applied. Therefore, centered text may appear off-center. The following text would appear centered if Max Letters To Show allowed the entire text to be displayed, but since it is cut-off, it appears off-center.
OutlineThickness can be used to create an outline around a font. The outline is saved in the .png of the font itself, so each value for OutlineThickness results in a new .fnt file and associated .png files created in the FontCache folder.
The OutlineThickness can be set on a Text object like any other variable.
OutlineThickness changes appear in the Gum window.
The Red value controls the color of the Text object. The Red value has a range of 0 - 255. The Red value combines with the Blue and Green values to create the final color.
For more information on working with color, see the .
Text Overflow Horizontal Mode controls how truncated words are treated. Horizontal truncation is only performed if the Text instance is using a Text Overflow Vertical Mode of Truncate Line. For information more see the Text Overflow Vertical Mode page.
Truncate Word results in words which do not fit in the Text instance's bounds being completely removed.
The following animation shows words (and lines) truncated in response to changing a Text instance's size.
Ellipsis Letter results in letters which do not fit in the Text instance's bounds being replaced by an ellipsis (...) which fits in the bounds of the Text instance.
The following animation shows words (and lines) replaced by ellipsis in response to changing a Text instance's size.
Note that additional letters must be removed from the Text instance so the added ellipsis fits in the Text instance's bounds.
Text objects have a Text property which controls the displayed text. By default this value is set to "Hello".
The Text property can be changed in the multi-line edit window.
Text will wrap according to the Text object's Width.
The enter key can be used to add new lines to text.
Gum text supports inline styling using BBCode-like syntax. To add inline styling, surround text with variable assignment tags as shown in the following screenshot:
The following table shows the available variables that can be used for inline styling:
Color
This is [Color=orange]orange[/Color] text.
Red Green Blue
This is [Red=0][Green=128][Blue=255]light blue[/Red][/Green][/Blue] text.
FontScale
This is [FontScale=2]big[/FontScale] text.
IsBold
This is [IsBold=true]bold[/IsBold] text.
IsItalic
This is [IsItalic=true]italic[/IsItalic] text.
Font
This is [Font=Papyrus]Papyrus[/Font] text.
FontSize
This is [FontSize=36]bigger[/FontSize] text.
OutlineThickness
This is [OutlineThickness=2]outlined[/OutlineThickness] text.
Note that changing Font and FontSize results in new Fonts created in the Font Cache.
BBCode can span multiple lines, whether the newlines happen due to line wrapping or through the addition of newlines in the text.
Multiple tags can overlap each other allowing you to combine tags for a single piece of text. For example, the following sets text to both bold and orange:
Styles can contain other styles as many levels deep as necessary.