Skip to content

Commit 61c29b3

Browse files
committed
Chapter 8 updated with new atlas
1 parent a11bbeb commit 61c29b3

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

  • articles/tutorials/building_2d_games/08_the_sprite_class

articles/tutorials/building_2d_games/08_the_sprite_class/index.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@ We can simplify this process by adding a sprite creation method to the `TextureA
7272

7373
Let's adjust our game now to use the `Sprite` class instead of just the texture regions. Replace the contents of *Game1.cs* with the following:
7474

75-
[!code-csharp[](./snippets/game1.cs?highlight=11-15,34-38,61-65)]
75+
[!code-csharp[](./snippets/game1.cs?highlight=11-15,34-40,63-67)]
7676

7777
The key changes in this implementation are:
7878

7979
- The `_slime` and `_bat` members were changed from `TextureRegion` to `Sprite`.
80-
- In [**LoadContent**](xref:Microsoft.Xna.Framework.Game.LoadContent) the `_slime` and `_bat` sprites are now created using the new `TextureAtlas.CreateSprite` method.
80+
- In [**LoadContent**](xref:Microsoft.Xna.Framework.Game.LoadContent)
81+
- The `_slime` and `_bat` sprites are now created using the new `TextureAtlas.CreateSprite` method.
82+
- Both the `_slime` and `_bat` sprites are given a scale of 4.0f.
8183
- In [**Draw**](xref:Microsoft.Xna.Framework.Game.Draw(Microsoft.Xna.Framework.GameTime)), the draw calls were updated to use the `Sprite.Draw` method.
8284

8385
Running the game now will produce the same result as in the previous chapter.
@@ -86,6 +88,9 @@ Running the game now will produce the same result as in the previous chapter.
8688
|:----------------------------------------------------------------------------------------------------------------------------------------:|
8789
| **Figure 8-1: The slime and bat sprites being rendered in the upper-left corner of the game window** |
8890

91+
> [!NOTE]
92+
> Notice how even though we increased the scale of both sprites, the bat sprite is still only 10px to the right of the bat. This is because the `Width` property we created for the `Sprite` class takes into account the scale factor of the sprite as well.
93+
8994
Try adjusting the various properties available for the slime and the bat sprites to see how they affect the rendering.
9095

9196
## Conclusion

articles/tutorials/building_2d_games/08_the_sprite_class/snippets/game1.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ protected override void LoadContent()
3333

3434
// Create the slime sprite from the atlas.
3535
_slime = atlas.CreateSprite("slime");
36+
_slime.Scale = new Vector2(4.0f, 4.0f);
3637

3738
// Create the bat sprite from the atlas.
3839
_bat = atlas.CreateSprite("bat");
40+
_bat.Scale = new Vector2(4.0f, 4.0f);
3941

4042
base.LoadContent();
4143
}

0 commit comments

Comments
 (0)