You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "Learn how to create custom UI components with animations and visual styling in Gum."
4
4
---
5
5
6
-
In the [previous chapter](../20_implementing_ui_with_gum/index.md), we implemented a functional UI system for our game using the Gum framework. While the UI is now fully operational, it uses Gum's default styling. This default styling is good for quickly iterating when building the UI, but it does not match the game's visuals. A welldesigned UI should not only be functional but also complement the game's overall visual style to create a cohesive experience.
6
+
In the [previous chapter](../20_implementing_ui_with_gum/index.md), we implemented a functional UI system for our game using the Gum framework. While the UI is now fully operational, it uses Gum's default styling. This default styling is good for quickly iterating when building the UI, but it does not match the game's visuals. A well-designed UI should not only be functional but also complement the game's overall visual style to create a cohesive experience.
7
7
8
-
In this chapter you will:
8
+
In this chapter, you will:
9
9
10
10
- Learn about Gum's visual customization system and component hierarchy.
11
11
- Understand how animation chains and visual states work in Gum.
@@ -160,7 +160,7 @@ Next, add this font file to your content project using the MGCB Editor:
160
160
|**Figure 21-2: The MGCB Editor with the 04b_30.fnt added to the fonts folder and the Build property set to Copy**|
161
161
162
162
> [!NOTE]
163
-
> When the *.fnt* font file was generated using the [AngelCode Bitmap Font Generator](https://www.angelcode.com/products/bmfont/), the graphics from the *.png* file that it produces was copied over into our existing texture atlas. By doing this, it allows Gum to render the visuals for elements and the text from the same atlas, reducing texture swapping.
163
+
> When the *.fnt* font file was generated using the [AngelCode Bitmap Font Generator](https://www.angelcode.com/products/bmfont/), the graphics from the *.png* file that it produces were copied over into our existing texture atlas. By doing this, it allows Gum to render the visuals for elements and the text from the same atlas, reducing texture swapping.
164
164
>
165
165
> The font file references our existing texture atlas using a relative path that points to the atlas image.
166
166
>
@@ -184,9 +184,9 @@ Now that we have all our resources prepared, we can create custom versions of th
184
184
185
185
Our first custom component is an `AnimatedButton` that inherits from Gum's base `Button` class. This button uses the game's existing texture atlas for its visual appearance and animates when focused.
186
186
187
-
By default all Gum components provide a Visual property which can be cast to a type specific to the particular control. By convention the visual type is named the same as the component with the word `Visual`appened. For example, we will be casting the AnimatedButton's Visual property to `ButtonVisual` to access button-specific properties.
187
+
By default, all Gum components provide a Visual property which can be cast to a type specific to the particular control. By convention, the visual type is named the same as the component with the word `Visual`appended. For example, we will be casting the AnimatedButton's Visual property to `ButtonVisual` to access button-specific properties.
188
188
189
-
This new `AnimatedButton` class casts the Visual property to `ButtonVisual` and modifies the button-specific properties such as background and text.
189
+
This new `AnimatedButton` class casts the Visual property to `ButtonVisual` and modifies the button-specific properties, such as background and text.
190
190
191
191
First, in the *DungeonSlime* project (your main game project), create a new folder named `UI` to store our custom UI components. Next, in that `UI` folder, create a new file called `AnimatedButton.cs` and add the following code to it:
192
192
@@ -196,7 +196,7 @@ Next, we will examine the key aspects of this new `AnimatedButton` implementatio
196
196
197
197
#### ButtonVisual
198
198
199
-
As mentioned earlier, we first access the `Visual` object and cast it to a `ButtonVisual`. Doing so gives us access to button-specific properties including individual elements (such as the text and background visuals) as well as the states that are applied when the button is hovered or pressed.
199
+
As mentioned earlier, we first access the `Visual` object and cast it to a `ButtonVisual`. Doing so gives us access to button-specific properties, including individual elements (such as the text and background visuals) as well as the states that are applied when the button is hovered or pressed.
200
200
201
201
We can modify the Visual to give it the appropriate size.
202
202
@@ -206,15 +206,15 @@ The `WidthUnits` property set to `RelativeToChildren` means the container autom
206
206
207
207
#### Nine-slice Background
208
208
209
-
`ButtonVisual` provides a `Background` which we can modify. This is of type `NineSliceRuntime` which is a special graphic that can be stretch while preserving its corners and edges:
209
+
`ButtonVisual` provides a `Background` which we can modify. This is of type `NineSliceRuntime`, which is a special graphic that can be stretched while preserving its corners and edges:
The `TextureAddress` property is set to `Custom` so we can specify exactly which portion of the atlas texture to use, while `Dock(Dock.Fill)` ensure the background fills the entire button area. The portion of the atlas is assigned using AnimationChains, which are discussed later in this tutorial.
214
214
215
215
#### Text
216
216
217
-
`ButtonVisual` also provides a customizable `Text` property. In this case we assign the font, color, and size.
217
+
`ButtonVisual` also provides a customizable `Text` property. In this case, we assign the font, color, and size.
@@ -231,7 +231,7 @@ Each animation frame specifies the coordinates within our texture atlas to displ
231
231
232
232
#### States and Categories
233
233
234
-
In Gum, each control type has a specific category name that identifies its state collection. `ButtonVisual` provides access to ready-made states and catgories which we can modify. Before we speicfy how a state should modify the button's appearance, we clear out all existing functionality so that we can fully control the states:
234
+
In Gum, each control type has a specific category name that identifies its state collection. `ButtonVisual` provides access to ready-made states and categories which we can modify. Before we specify how a state should modify the button's appearance, we clear out all existing functionality so that we can fully control the states:
0 commit comments