Skip to content

Redraft/chapter 05 #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
287 changes: 139 additions & 148 deletions articles/tutorials/building_2d_games/05_content_pipeline/index.md

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ protected override void Initialize()
protected override void LoadContent()
{
_logo = Content.Load<Texture2D>("images/logo");
base.LoadContent();
}

protected override void Update(GameTime gameTime)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ Add this texture atlas to your content project using the MGCB Editor:

First, we will explore creating the texture atlas and defining the texture regions directly in code. Replace the contents of `Game1.cs` with the following:

[!code-csharp[](./snippets/game1/textureatlas_usage.cs?highlight=5,11-15,31-47,67-77)]
[!code-csharp[](./snippets/game1/textureatlas_usage.cs?highlight=5,11-15,31-47,65-75)]

The key changes in this implementation are:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ protected override void LoadContent()

// retrieve the bat region from the atlas.
_bat = atlas.GetRegion("bat");

base.LoadContent();
}

protected override void Update(GameTime gameTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ protected override void LoadContent()

// retrieve the bat region from the atlas.
_bat = atlas.GetRegion("bat");

base.LoadContent();
}

protected override void Update(GameTime gameTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ We can simplify this process by adding a sprite creation method to the `TextureA

Now we can adjust our game now to use the `Sprite` class instead of just the texture regions. Update the contents of `Game1.cs` with the following:

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

The key changes in this implementation are:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ protected override void LoadContent()
// Create the bat sprite from the atlas.
_bat = atlas.CreateSprite("bat");
_bat.Scale = new Vector2(4.0f, 4.0f);

base.LoadContent();
}

protected override void Update(GameTime gameTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ We can simplify this process by adding an animated sprite creation method to the

We can now adjust our game now to use the `AnimatedSprite` class to see our sprites come to life. Update the contents of `Game1.cs` with the following:

[!code-csharp[](./snippets/game1.cs?highlight=11-15,34-40,50-54)]
[!code-csharp[](./snippets/game1.cs?highlight=11-15,34-40,48-52)]

Here are the key changes in this implementation:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ protected override void LoadContent()
// Create the bat animated sprite from the atlas.
_bat = atlas.CreateAnimatedSprite("bat-animation");
_bat.Scale = new Vector2(4.0f, 4.0f);

base.LoadContent();
}

protected override void Update(GameTime gameTime)
Expand Down
856 changes: 429 additions & 427 deletions articles/tutorials/building_2d_games/10_handling_input/index.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ protected override void LoadContent()
// Create the bat animated sprite from the atlas.
_bat = atlas.CreateAnimatedSprite("bat-animation");
_bat.Scale = new Vector2(4.0f, 4.0f);

base.LoadContent();
}

protected override void Update(GameTime gameTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ The key changes to the `Core` class are:

Now we can update our `Game1` class to use the new input management system through the `Core` class. Open `Game1.cs` in the game project and update it to the following:

[!code-csharp[](./snippets/game1.cs?highlight=1,7,77,83,89,95,101,109,114,117,121,127,129-130,135,141,147,153)]
[!code-csharp[](./snippets/game1.cs?highlight=6,74,80,86,92,98,106,111,114,118,124,126-127,132,138,144,150)]

The key changes to the `Game1` class are:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ protected override void LoadContent()
// Create the bat animated sprite from the atlas.
_bat = atlas.CreateAnimatedSprite("bat-animation");
_bat.Scale = new Vector2(4.0f, 4.0f);

base.LoadContent();
}

protected override void Update(GameTime gameTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ If you run the game right now and move the slime around, you will notice a few i

We can now implement these features using collision detection and response in our game. In the *DungeonSlime* project (your main game project), open the `Game1.cs` file and make the following changes to the `Game1` class:

[!code-csharp[](./snippets/game1.cs?highlight=25-29,40-45,81-181,186-198,298-299)]
[!code-csharp[](./snippets/game1.cs?highlight=1,5,25-29,40-45,79-179,184-196,296-297)]

The key changes made here are:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ protected override void LoadContent()
// Create the bat animated sprite from the atlas.
_bat = atlas.CreateAnimatedSprite("bat-animation");
_bat.Scale = new Vector2(4.0f, 4.0f);

base.LoadContent();
}

protected override void Update(GameTime gameTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ This tilemap configuration creates a simple dungeon layout with walls around the

With all of the assets now in place and configured, we can update the `Game1` class to load the tilemap and draw it. We will also need to update the collision logic so that the boundary is no longer the edge of the screen, but instead the edges of the wall tiles of the tilemap. Open `Game1.cs` and make the following updates:

[!code-csharp[](./snippets/game1.cs?highlight=31-35,46-61,80-82,114,116,118,120,123,125,127,129,147,150,152,155,158,161,163,166,181-183,305-306)]
[!code-csharp[](./snippets/game1.cs?highlight=31-35,46-61,80-82,112,114,116,128,121,123,125,127,145,148,150,153,156,159,161,164,179-181,303-304)]

The key changes to the `Game1` class include:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ protected override void LoadContent()
// Create the tilemap from the XML configuration file.
_tilemap = Tilemap.FromFile(Content, "images/tilemap-definition.xml");
_tilemap.Scale = new Vector2(4.0f, 4.0f);

base.LoadContent();
}

protected override void Update(GameTime gameTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ Add these files to your content project using the MGCB Editor:

Next, open the `Game1.cs` file and update it to the following:

[!code-csharp[](./snippets/game1.cs?highlight=3,6,39-43,92-111,205-206,224-225)]
[!code-csharp[](./snippets/game1.cs?highlight=3,6,39-43,92-111,203-204,222-223)]

The key changes here are:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ protected override void LoadContent()

// Set the theme music to repeat.
MediaPlayer.IsRepeating = true;

base.LoadContent();
}

protected override void Update(GameTime gameTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ The key changes made here are:

Next, update the `Game1` class to use the audio controller for audio playback. Open `Game1.cs` and make the following updates:

[!code-csharp[](./snippets/game1.cs?highlight=45-46,77-78,104-105,199-200,218-219,272-290)]
[!code-csharp[](./snippets/game1.cs?highlight=45-46,77-78,104-105,197-198,216-217,270-288)]

> [!NOTE]
> Note there were a lot of replacements in the `LoadContent` method, switching from loading and initializing the background Song and replacing it with a call to the new `AudioController` to do all the work managing the Song reference. Much cleaner.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ protected override void LoadContent()

// Load the background theme music
_themeSong = Content.Load<Song>("audio/theme");

base.LoadContent();
}

protected override void Update(GameTime gameTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ The key changes here are:

Finally, open the `Game1.cs` file and make the following changes:

[!code-csharp[](./snippets/game1.cs?highlight=48-58,93-99,129-130,246-247,391-402)]
[!code-csharp[](./snippets/game1.cs?highlight=48-58,93-99,129-130,244-245,389-400)]

The key changes made are:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ protected override void LoadContent()

// Load the font
_font = Content.Load<SpriteFont>("fonts/04B_30");

base.LoadContent();
}

protected override void Update(GameTime gameTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ protected override void Initialize()

protected override void LoadContent()
{
base.LoadContent();

// Load the background theme music
_themeSong = Content.Load<Song>("audio/theme");
}
Expand Down