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
Copy file name to clipboardExpand all lines: articles/tutorials/building_2d_games/05_content_pipeline/index.md
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -88,7 +88,7 @@ To open the *Content.mgcb* content project file in the MGCB Editor using the dot
88
88
> dotnet tool restore
89
89
>```
90
90
>
91
-
> This should restore the tool with the version that is configured. If at any time you upte your `dotnet-tools.json` configuration, e.g. when upgrading to a newer version of MonoGame, **you will need to run this command again**
91
+
> This should restore the tool with the version that is configured. If at any time you update your `dotnet-tools.json` configuration, e.g. when upgrading to a newer version of MonoGame, **you will need to run this command again**
@@ -113,7 +113,7 @@ To add assets (such as textures, audio, etc) to the content project:
113
113
When adding assets to the content project, a pop-up dialog will appear with the following options:
114
114
115
115
- **Copy the file to the folder**: Creates a duplicate of the file inside your project's Content folder. This creates an independent copy, meaning any later changes to the original file wo not affect your project.
116
-
- **Add a link**: Creates a reference to the original file without making a copy. This maintains a connection to the source file, so any updates to the original will be included when you build. Note that the link uses a path relative to the Content.mgcb file, so if either the source file or your project moves, you will need to re-establish the link.
116
+
- **Add a link**: Creates a reference to the original file without making a copy. This maintains a connection to the source file, so any updates to the original will be included when you build. Note that the link uses a path relative to the `Content.mgcb` file, so if either the source file or your project moves, you will need to re-establish the link.
117
117
- **Skip**: Cancels adding the current file while continuing with any other selected files.
@@ -125,15 +125,15 @@ When adding assets to the content project, a pop-up dialog will appear with the
125
125
To create a new asset using one of the built-in asset types in the MGCB Editor:
126
126
127
127
1. In the Project panel, select the folder where you want to add the new asset. If you want to add it to the root, select the main *Content* node.
128
-
2. Right-click on the selected folder and choose *Add > New Item...* from the context menu.
128
+
2. Right-click on the selected folder and choose `Add > New Item...` from the context menu.
129
129
3. In the dialog that appears, select the type of asset you want to create from the list of available built-in types:
130
130
- **Effect (.fx)**: A shader file that creates custom visual effects by controlling how graphics are rendered on the GPU.
131
131
- **SpriteFont Description (.spritefont)**: A configuration file that defines how text will be displayed in your game, including character set and font properties.
132
132
- **Sprite Effect (.fx)**: A shader specifically designed for use with 2D sprites to create special visual effects.
133
133
- **Xml Content (.xml)**: A structured data file for storing game information like levels, dialogues, or configuration settings.
134
134
- **LocalizedSpriteFont Description (.spritefont)**: A configuration file for creating fonts with support for multiple languages.
135
135
4. Enter a name for your new asset in the *Name* field.
136
-
5. Click *Create* to add the new asset to your project.
136
+
5. Click `Create` to add the new asset to your project.
137
137
138
138
|  |
Copy file name to clipboardExpand all lines: articles/tutorials/building_2d_games/21_customizing_gum_ui/index.md
+29-26Lines changed: 29 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -24,23 +24,26 @@ Every customized UI component in Gum starts with a top-level container that hold
24
24
25
25
The container hierarchy follows a parent-child relationship:
26
26
27
-
- The top-level container manages the overall size and positioning of the component
28
-
- Visual elements like backgrounds, text, and icons are added as children
29
-
- Child elements can be positioned relative to their parent container
30
-
- Child elements can also be nested within other children, creating deeper hierarchies
27
+
- The top-level container manages the overall size and positioning of the component.
28
+
- Visual elements like backgrounds, text, and icons are added as children.
29
+
- Child elements can be positioned relative to their parent container.
30
+
- Child elements can also be nested within other children, creating deeper hierarchies.
31
31
32
32
This hierarchical structure allows you to build complex UI components from simpler parts, with each part playing a specific role in the overall design.
33
33
34
34
### Size Relationships with Width and WidthUnits
35
35
36
36
One powerful feature of Gum is how it handles size relationships between parent and child elements. By using different `WidthUnits` values, you can create dependencies that flow in different directions:
37
37
38
-
-**RelativeToChildren**: A parent container can size itself based on its children
39
-
-**PercentageOfParent**: A child element can size itself as a percentage of its parent
40
-
-**Absolute**: An element can have a fixed pixel size
41
-
-**RelativeToParent**: An element can size itself relative to a specific container
38
+
-**RelativeToChildren**: A parent container can size itself based on its children.
39
+
-**PercentageOfParent**: A child element can size itself as a percentage of its parent.
40
+
-**Absolute**: An element can have a fixed pixel size.
41
+
-**RelativeToParent**: An element can size itself relative to a specific container.
42
42
43
-
For example, a button might use a text element with `WidthUnits` set to `RelativeToChildren`, which means the text will be exactly the size needed to display its content. The button's container might use `RelativeToChildren` with some additional padding, allowing the button to automatically resize based on its text content.
43
+
For example:
44
+
45
+
- A button might use a text element with `WidthUnits` set to `RelativeToChildren`, which means the text will be exactly the size needed to display its content.
46
+
- The button's container might use `RelativeToChildren` with some additional padding, allowing the button to automatically resize based on its text content.
44
47
45
48
Although we have not explicitly assigned WidthUnits and HeightUnits in our code, we have indirectly set these values by calling the Visual's `Dock` method. Specifically, by passing `Dock.Fill` as the parameter, `WidthUnits` and `HeightUnits` are both set to `RelativeToParent`.
46
49
@@ -83,9 +86,9 @@ To convert from pixel coordinates to normalized values, you divide the pixel pos
83
86
84
87
Rather than directly modifying properties when UI elements change state (like when a button is focused), Gum uses a state-based system. Each control type has a specific category name that identifies its collection of states:
85
88
86
-
- Buttons use `Button.ButtonCategoryName`
87
-
- Sliders use `Slider.SliderCategoryName`
88
-
- Other control types have their own category names
89
+
- Buttons use `Button.ButtonCategoryName`.
90
+
- Sliders use `Slider.SliderCategoryName`.
91
+
- Other control types have their own category names.
89
92
90
93
Within each category, you define named states that correspond to the control's possible conditions:
91
94
@@ -114,7 +117,7 @@ Before we create our custom components, we need to update the game's resources t
114
117
115
118
### Update the Texture Atlas
116
119
117
-
Before we can start, we first need to update the *atlas.png* texture atlas file for the game. This new version of the texture atlas includes:
120
+
First need to update the *atlas.png* texture atlas file for the game. This new version of the texture atlas includes:
118
121
119
122
- The characters for the font, generated using Bitmap Font Generator (BMFont)
120
123
- The sprites for the UI components we will create
@@ -139,11 +142,11 @@ First, download the *.fnt* file by right-clicking the following link and saving
139
142
140
143
Next, add this font file to your content project using the MGCB Editor:
141
144
142
-
1. Open the *Content.mgcb* content project file in the MGCB Editor.
143
-
2. Right-click the *fonts* folder and choose *Add* > *Existing Item...*.
144
-
3. Navigate to and select the *04b_30.fnt* file you just downloaded.
145
-
4. In the Properties panel, change the *Build Action* to *Copy*. The MonoGame Content Pipeline cannot process *.fnt* files; we just need it to copy it so we can give it to Gum.
146
-
5. Save the changes and close the MGCB Editor.
145
+
1. Open the `Content.mgcb` content project file in the MGCB Editor.
146
+
2. Right-click the `fonts` folder and choose `Add > Existing Item...`.
147
+
3. Navigate to and select the `04b_30.fnt` file you just downloaded.
148
+
4. In the Properties panel, change the `Build Action` to `Copy`. The MonoGame Content Pipeline cannot process *.fnt* files; we just need it to copy it so we can give it to Gum.
149
+
5.**Save the changes and close the MGCB Editor.**
147
150
148
151
||
@@ -162,7 +165,7 @@ In [Chapter 18](../18_texture_sampling/index.md#texture-coordinates) we discusse
162
165
163
166
Since [Gum also uses this coordinate system](#animation-chains), we will update the `TextureRegion` class to easily provide these values for any given region.
164
167
165
-
Open the *TextureRegion.cs* file in the *MonoGameLibrary* project and add the following properties to the `TextureRegion` class:
168
+
Open the `TextureRegion.cs` file in the *MonoGameLibrary* project and add the following properties to the `TextureRegion` class:
@@ -174,11 +177,11 @@ Now that we have all our resources prepared, we can create custom versions of th
174
177
175
178
Our first custom component will be an `AnimatedButton` that inherits from Gum's base `Button` class. This button will use the game's existing texture atlas for its visual appearance and provide animation when focused.
176
179
177
-
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:
180
+
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:
178
181
179
182
[!code-csharp[](./snippets/animatedbutton.cs)]
180
183
181
-
Next, we will examine the key aspects of this implementation:
184
+
Next, we will examine the key aspects of this new `AnimatedButton`implementation:
182
185
183
186
#### Top-level Container
184
187
@@ -243,15 +246,15 @@ This creates a more responsive interface by immediately focusing elements that t
243
246
244
247
Now we will create a custom `OptionsSlider` class to style the volume sliders. This class inherits from Gum's base `Slider` class and provides a styled appearance consistent with the game's visual theme.
245
248
246
-
In the *UI* folder fo the *DungeonSlime* project (your main game project), create a new file called *OptionsSlider.cs* and add the following code to it:
249
+
In the `UI` folder of the *DungeonSlime* project (your main game project), create a new file called `OptionsSlider.cs` and add the following code to it:
247
250
248
251
[!code-csharp[](./snippets/optionsslider.cs)]
249
252
250
253
The `OptionsSlider` is more complex than then [`AnimatedButton`](#the-animatedbutton-class) because it contains more visual elements. Below are the key aspects of this implementation:
251
254
252
255
#### Slider Components
253
256
254
-
Our custom slider consists of several components
257
+
Walking through the `OptionsSlider` implementation, it consists of several components
255
258
256
259
1. A background container with a label for the slider.
257
260
2. An inner container that holds the slider track.
@@ -293,9 +296,9 @@ Now that we have created our custom controls, we need to update our game scenes
293
296
294
297
### Updating the TitleScene
295
298
296
-
First, open the *TitleScene.cs* file in the game project and add the following using declaration to the top of the `TitleScene` class:
299
+
First, open the `TitleScene.cs` file in the game project and add the following using declaration to the top of the `TitleScene` class:
Next, update both the `_optionsButton` and the `_optionsBackButton` fields to be of our new [`AnimatedButton`](#the-animatedbutton-class) type, and add a new field to store a reference to the texture atlas in.
301
304
@@ -319,7 +322,7 @@ Finally, update the `CreateOptionsPanel` method so that:
319
322
320
323
### Updating the GameScene
321
324
322
-
Next, open the *GameScene.cs* file in the game project and add the following using declaration to the top of the `GameScene` class:
325
+
Next, open the `GameScene.cs` file in the game project and add the following using declaration to the top of the `GameScene` class:
0 commit comments