Skip to content

Commit 69b3f8b

Browse files
Merge pull request MonoGame#8 from AristurtleDev/reorginize
Rework Chapters
2 parents 6ca06bf + 3c01abe commit 69b3f8b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1646
-2047
lines changed

articles/toc.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,12 @@
118118
href: tutorials/building_2d_games/02_getting_started/
119119
- name: "03: The Game1 File"
120120
href: tutorials/building_2d_games/03_the_game1_file/
121-
- name: "04: Working with Textures"
122-
href: tutorials/building_2d_games/04_working_with_textures/
123-
- name: "05: Optimizing Texture Rendering"
124-
href: tutorials/building_2d_games/05_optimizing_texture_rendering/
121+
- name: "04: Content Pipeline"
122+
href: tutorials/building_2d_games/04_content_pipeline/
123+
- name: "05: Working with Textures"
124+
href: tutorials/building_2d_games/05_working_with_textures/
125+
- name: "06: Optimizing Texture Rendering"
126+
href: tutorials/building_2d_games/06_optimizing_texture_rendering/
125127
- name: Console Access
126128
href: console_access.md
127129
- name: Help and Support

articles/tutorials/building_2d_games/04_content_pipeline/index.md

Lines changed: 220 additions & 0 deletions

articles/tutorials/building_2d_games/04_working_with_textures/images/content-pipeline-workflow.svg

Lines changed: 0 additions & 999 deletions
This file was deleted.

articles/tutorials/building_2d_games/04_working_with_textures/index.md

Lines changed: 0 additions & 406 deletions
This file was deleted.

articles/tutorials/building_2d_games/05_optimizing_texture_rendering/index.md

Lines changed: 0 additions & 635 deletions
This file was deleted.

articles/tutorials/building_2d_games/05_working_with_textures/index.md

Lines changed: 528 additions & 0 deletions

articles/tutorials/building_2d_games/06_optimizing_texture_rendering/index.md

Lines changed: 691 additions & 0 deletions
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using Microsoft.Xna.Framework;
2+
using Microsoft.Xna.Framework.Graphics;
3+
using Microsoft.Xna.Framework.Input;
4+
using MonoGameLibrary.Graphics;
5+
6+
namespace MonoGameSnake;
7+
8+
public class Game1 : Game
9+
{
10+
private GraphicsDeviceManager _graphics;
11+
private SpriteBatch _spriteBatch;
12+
private TextureRegion _slime;
13+
private TextureRegion _bat;
14+
15+
public Game1()
16+
{
17+
_graphics = new GraphicsDeviceManager(this);
18+
Content.RootDirectory = "Content";
19+
IsMouseVisible = true;
20+
}
21+
22+
protected override void Initialize()
23+
{
24+
// TODO: Add your initialization logic here
25+
26+
base.Initialize();
27+
}
28+
29+
protected override void LoadContent()
30+
{
31+
_spriteBatch = new SpriteBatch(GraphicsDevice);
32+
33+
// Load the atlas texture using the content manager
34+
Texture2D atlasTexture = Content.Load<Texture2D>("images/atlas");
35+
36+
// Create a TextureAtlas instance from the atlas
37+
TextureAtlas atlas = new TextureAtlas(atlasTexture);
38+
39+
// Create and add the slime and bad regions
40+
atlas.AddRegion("slime", 0, 160, 40, 40);
41+
atlas.AddRegion("bat", 80, 160, 40, 40);
42+
43+
// Retrieve the slime and bat regions
44+
_slime = atlas.GetRegion("slime");
45+
_bat = atlas.GetRegion("bat");
46+
}
47+
48+
protected override void Update(GameTime gameTime)
49+
{
50+
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
51+
Exit();
52+
53+
base.Update(gameTime);
54+
}
55+
56+
protected override void Draw(GameTime gameTime)
57+
{
58+
GraphicsDevice.Clear(Color.CornflowerBlue);
59+
60+
_spriteBatch.Begin();
61+
62+
// Draw the slime texture region.
63+
_slime.Draw(_spriteBatch, Vector2.One, Color.White);
64+
65+
// Draw the bat texture region 10px to the right of the slime.
66+
_bat.Draw(_spriteBatch, new Vector2(_slime.Width + 10, 0), Color.White);
67+
68+
_spriteBatch.End();
69+
70+
base.Draw(gameTime);
71+
}
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using Microsoft.Xna.Framework;
2+
using Microsoft.Xna.Framework.Graphics;
3+
using Microsoft.Xna.Framework.Input;
4+
using MonoGameLibrary.Graphics;
5+
6+
namespace MonoGameSnake;
7+
8+
public class Game1 : Game
9+
{
10+
private GraphicsDeviceManager _graphics;
11+
private SpriteBatch _spriteBatch;
12+
private TextureRegion _slime;
13+
private TextureRegion _bat;
14+
15+
public Game1()
16+
{
17+
_graphics = new GraphicsDeviceManager(this);
18+
Content.RootDirectory = "Content";
19+
IsMouseVisible = true;
20+
}
21+
22+
protected override void Initialize()
23+
{
24+
// TODO: Add your initialization logic here
25+
26+
base.Initialize();
27+
}
28+
29+
protected override void LoadContent()
30+
{
31+
_spriteBatch = new SpriteBatch(GraphicsDevice);
32+
33+
// Create the texture atlas from the XML configuration file
34+
TextureAtlas atlas = TextureAtlas.FromFile(Content, "images/atlas-definition.xml");
35+
36+
// Retrieve the slime and bat regions
37+
_slime = atlas.GetRegion("slime");
38+
_bat = atlas.GetRegion("bat");
39+
}
40+
41+
protected override void Update(GameTime gameTime)
42+
{
43+
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
44+
Exit();
45+
46+
base.Update(gameTime);
47+
}
48+
49+
protected override void Draw(GameTime gameTime)
50+
{
51+
GraphicsDevice.Clear(Color.CornflowerBlue);
52+
53+
_spriteBatch.Begin();
54+
55+
// Draw the slime texture region.
56+
_slime.Draw(_spriteBatch, Vector2.One, Color.White);
57+
58+
// Draw the bat texture region 10px to the right of the slime.
59+
_bat.Draw(_spriteBatch, new Vector2(_slime.Width + 10, 0), Color.White);
60+
61+
_spriteBatch.End();
62+
63+
base.Draw(gameTime);
64+
}
65+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using Microsoft.Xna.Framework;
2+
using Microsoft.Xna.Framework.Graphics;
3+
using Microsoft.Xna.Framework.Input;
4+
using MonoGameLibrary.Graphics;
5+
6+
namespace MonoGameSnake;
7+
8+
public class Game1 : Game
9+
{
10+
private GraphicsDeviceManager _graphics;
11+
private SpriteBatch _spriteBatch;
12+
private TextureRegion _slime;
13+
14+
public Game1()
15+
{
16+
_graphics = new GraphicsDeviceManager(this);
17+
Content.RootDirectory = "Content";
18+
IsMouseVisible = true;
19+
}
20+
21+
protected override void Initialize()
22+
{
23+
// TODO: Add your initialization logic here
24+
25+
base.Initialize();
26+
}
27+
28+
protected override void LoadContent()
29+
{
30+
_spriteBatch = new SpriteBatch(GraphicsDevice);
31+
32+
// Load the atlas texture using the content manager
33+
Texture2D atlasTexture = Content.Load<Texture2D>("images/atlas");
34+
35+
// create a texture region from the atlas for the slime sprite
36+
_slime = new TextureRegion(atlasTexture, 0, 160, 40, 40);
37+
}
38+
39+
protected override void Update(GameTime gameTime)
40+
{
41+
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
42+
Exit();
43+
44+
base.Update(gameTime);
45+
}
46+
47+
protected override void Draw(GameTime gameTime)
48+
{
49+
GraphicsDevice.Clear(Color.CornflowerBlue);
50+
51+
_spriteBatch.Begin();
52+
53+
// Draw the slime texture region
54+
_slime.Draw(_spriteBatch, Vector2.One, Color.White);
55+
56+
_spriteBatch.End();
57+
58+
base.Draw(gameTime);
59+
}
60+
}

articles/tutorials/building_2d_games/index.md

Lines changed: 4 additions & 3 deletions

0 commit comments

Comments
 (0)