Skip to content

Commit 9395362

Browse files
committed
Rewrite all chapters to use new atlas for gum integration in 19
1 parent b424461 commit 9395362

File tree

8 files changed

+82
-7
lines changed

8 files changed

+82
-7
lines changed
-37.5 KB
Loading

articles/tutorials/building_2d_games/16_working_with_spritefonts/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ First, we'll need to create a SpriteFont Definition. Open the *Content.mgcb* co
191191
192192
### Download the Font File
193193

194-
Next, right-click the following TTF font and choose "Save Link as..." and save it in the same directory as the *gameFont.spriteFont* file we just created.
194+
Next, right-click the following TTF font and choose "Save Link as..." and save it in the same directory as the *04B_30.spriteFont* file we just created.
195195

196196
- [04B_30.ttf](./files/04B_30.ttf)
197197

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
This file contains an xml description of a font, and will be read by the XNA
4+
Framework Content Pipeline. Follow the comments to customize the appearance
5+
of the font in your game, and to change the characters which are available to draw
6+
with.
7+
-->
8+
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
9+
<Asset Type="Graphics:FontDescription">
10+
11+
<!--
12+
Modify this string to change the font that will be imported.
13+
-->
14+
<FontName>04B_30.ttf</FontName>
15+
16+
<!--
17+
Size is a float value, measured in points. Modify this value to change
18+
the size of the font.
19+
-->
20+
<Size>87.5</Size>
21+
22+
<!--
23+
Spacing is a float value, measured in pixels. Modify this value to change
24+
the amount of spacing in between characters.
25+
-->
26+
<Spacing>0</Spacing>
27+
28+
<!--
29+
UseKerning controls the layout of the font. If this value is true, kerning information
30+
will be used when placing characters.
31+
-->
32+
<UseKerning>true</UseKerning>
33+
34+
<!--
35+
Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",
36+
and "Bold, Italic", and are case sensitive.
37+
-->
38+
<Style>Regular</Style>
39+
40+
<!--
41+
If you uncomment this line, the default character will be substituted if you draw
42+
or measure text that contains characters which were not included in the font.
43+
-->
44+
<!-- <DefaultCharacter>*</DefaultCharacter> -->
45+
46+
<!--
47+
CharacterRegions control what letters are available in the font. Every
48+
character from Start to End will be built and made available for drawing. The
49+
default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
50+
character set. The characters are ordered according to the Unicode standard.
51+
See the documentation for more information.
52+
-->
53+
<CharacterRegions>
54+
<CharacterRegion>
55+
<Start>&#32;</Start>
56+
<End>&#126;</End>
57+
</CharacterRegion>
58+
</CharacterRegions>
59+
</Asset>
60+
</XnaContent>
25.2 KB
Loading

articles/tutorials/building_2d_games/17_scenes/index.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,19 @@ The key changes here are:
111111
112112
## Updating the Game
113113

114-
With the scene architecture in place, the game can now be updated so that it is broken down into scenes. We'll create two scenes; a title scene and a gameplay scene.
114+
With the scene architecture in place, the game can now be updated so that it is broken down into scenes. We'll create two scenes; a title scene and a gameplay scene. First, however, we need to add an additional SpriteFont Description that will be used during the title scene to display the title of the game. Open the *Content.mgcb* content project file in the MGCB Editor and perform the following:
115+
116+
1. Right-click the *fonts* directory and choose *Add* > *New Item...*.
117+
2. Select *SpriteFont Description (.spritefont)* from the options
118+
3. Name the file *04B_30_5x.spritefont* and click *Create*.
119+
120+
| ![Figure 17-1: The *04B_30_5x.spritefont* file created in the MGCB Editor](./images/font_added.png) |
121+
| :-------------------------------------------------------------------------------------------------: |
122+
| **Figure 17-1: The *04B_30_5x.spritefont* file created in the MGCB Editor** |
123+
124+
Next, open the *04B_30_5x.spritefont* file and make the following changes:
125+
126+
[!code-xml[](./snippets/04B_30_5x.spritefont?highlight=4-5)]
115127

116128
### The Title Scene
117129

@@ -296,7 +308,7 @@ The `Game1` class is now much simpler as most of the game logic has been moved t
296308
Running the game now, we can see that once the game screen comes up, the title scene is displayed with the animated slime and the press enter prompt. The background music starts playing on this scene as well. Pressing enter from here will switch to the game scene where the game starts and we can play the game implemented thus far.
297309

298310
| ![Figure 17-2: The game launching with the title screen first, then transitioning to the game play screen when enter is pressed](./videos/gameplay.webm) |
299-
|:--------------------------------------------------------------------------------------------------------------------------------------------------------:|
311+
| :------------------------------------------------------------------------------------------------------------------------------------------------------: |
300312
| **Figure 17-2: The game launching with the title screen first, then transitioning to the game play screen when enter is pressed** |
301313

302314
## Conclusion

articles/tutorials/building_2d_games/17_scenes/snippets/titleFont.spritefont renamed to articles/tutorials/building_2d_games/17_scenes/snippets/04B_30_5x.spritefont

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
33
<Asset Type="Graphics:FontDescription">
44
<FontName>04B_30.ttf</FontName>
5-
<Size>85</Size>
5+
<Size>87.5</Size>
66
<Spacing>0</Spacing>
77
<UseKerning>true</UseKerning>
88
<Style>Regular</Style>

articles/tutorials/building_2d_games/17_scenes/snippets/gamescene.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,15 @@ public override void LoadContent()
110110

111111
// Create the slime animated sprite from the atlas.
112112
_slime = atlas.CreateAnimatedSprite("slime-animation");
113+
_slime.Scale = new Vector2(4.0f, 4.0f);
113114

114115
// Create the bat animated sprite from the atlas.
115116
_bat = atlas.CreateAnimatedSprite("bat-animation");
117+
_bat.Scale = new Vector2(4.0f, 4.0f);
116118

117-
// Load the tilemap from the XML configuration file.
119+
// Create the tilemap from the XML configuration file.
118120
_tilemap = Tilemap.FromFile(Content, "images/tilemap-definition.xml");
121+
_tilemap.Scale = new Vector2(4.0f, 4.0f);
119122

120123
// Load the bounce sound effect
121124
_bounceSoundEffect = Content.Load<SoundEffect>("audio/bounce");

articles/tutorials/building_2d_games/18_texture_sampling/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ Next, add this texture to your content project using the MGCB Editor:
163163

164164
Now that we have the background pattern texture added, let's update the `TitleScene` class to implement the scrolling background. Open the *TitleScene.cs* file in the game project and update it to the following
165165

166-
[!code-csharp[](./snippets/titlescene.cs?highlight=39-50,79-81,92-93,104-113,120-13)]
166+
[!code-csharp[](./snippets/titlescene.cs?highlight=39-50,79-81,92-93,104-113,120-123)]
167167

168168
The key changes here are
169169

@@ -177,7 +177,7 @@ The key changes here are
177177
- In `Draw`, a new sprite batch begin/end block is added that uses [**SamplerState.PointWrap**](xref:Microsoft.Xna.Framework.Graphics.SamplerState.PointWrap) and draws the background pattern to the destination rectangle using a source rectangle with the offset calculations.
178178

179179
> [!NOTE]
180-
> We use two separate sprite batch begin/end blocks for this. The first [**SamplerState.PointWrap**](xref:Microsoft.Xna.Framework.Graphics.SamplerState.PointWrap) to draw the background and the second uses [**SamplerState.PointClamp**](xref:Microsoft.Xna.Framework.Graphics.SamplerState.PointClamp) to draw the rest of the scene.
180+
> We use two separate sprite batch begin/end blocks for this. The first uses [**SamplerState.PointWrap**](xref:Microsoft.Xna.Framework.Graphics.SamplerState.PointWrap) to draw the background and the second uses [**SamplerState.PointClamp**](xref:Microsoft.Xna.Framework.Graphics.SamplerState.PointClamp) to draw the rest of the scene.
181181
>
182182
> This separation is necessary because changing the sampler state requires ending the current sprite batch and beginning a new one.
183183

0 commit comments

Comments
 (0)