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 2 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
280 changes: 134 additions & 146 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 @@ -172,7 +172,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 @@ -72,7 +72,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. Replace 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 @@ -170,7 +170,7 @@ We can simplify this process by adding an animated spirte creation method to the

We can now adjust our game now to use the `AnimatedSprite` class to see our sprites come to life. Replaces 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
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ For our game, we are going to implement keyboard and gamepad controls based on t

Open *Game1.cs* and update it with the following:

[!code-csharp[](./snippets/game1.cs?highlight=17-21,62-66,71-159,170)]
[!code-csharp[](./snippets/game1.cs?highlight=17-21,60-64,69-157,168)]

The key changes made here are:

Expand Down
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 @@ -372,7 +372,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=6,76,82,88,94,100,108,113,116,120,126,128-129,134,140,146,152)]
[!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 @@ -45,8 +45,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 @@ -296,7 +296,7 @@ If you run the game right now and move the slime around, you will notice a few i

To resolve this, we can update our game to implement these changes using collision detection and response. 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=1,5,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 @@ -176,7 +176,7 @@ Next, we need to add this configuration file to our content project with the MGC

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 @@ -172,7 +172,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 @@ -121,7 +121,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)]

The key changes made here are:

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 @@ -210,7 +210,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 @@ -128,8 +128,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