You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/tutorials/building_2d_games/10_the_animatedsprite_class/index.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ In MonoGame, we can create these animations by cycling through different regions
16
16
17
17
By drawing each frame sequentially over time, we create the illusion that the bat is flapping its wings. The speed at which we switch between frames determines how smooth or rapid the animation appears.
18
18
19
-
In this chapter, we'll build off of the `Sprite` class we created in [Chapter 09](../09_the_sprite_class/) to create an `AnimatedSprite` class we can use to bring animations to life.
19
+
In this chapter, we'll build off of the `Sprite` class we created in [Chapter 09](../09_the_sprite_class/index.md) to create an `AnimatedSprite` class we can use to bring animations to life.
Copy file name to clipboardExpand all lines: articles/tutorials/building_2d_games/11_handling_input/index.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ When you play a game, you need ways to control what's happening; using a keyboar
8
8
-[**Keyboard**](xref:Microsoft.Xna.Framework.Input.Keyboard): Detects which keys are being pressed.
9
9
-[**Mouse**](xref:Microsoft.Xna.Framework.Input.Mouse): Tracks mouse movement, button clicks, and scroll wheel use.
10
10
-[**GamePad**](xref:Microsoft.Xna.Framework.Input.GamePad): Manages controller input like button presses and thumbstick movement.
11
-
-[**TouchPanel**](xref:Microsoft.Xna.Framework.Input.TouchPanel): Manages touch input on devices with a touch panel such as mobile phones and tablets.
11
+
-[**TouchPanel**](xref:Microsoft.Xna.Framework.Input.Touch.TouchPanel): Manages touch input on devices with a touch panel such as mobile phones and tablets.
12
12
13
13
Each of these input types has a `GetState` method that, when called, checks what is happening with that device at that moment. Think of it like taking a snapshot; when you call `GetState`, MonoGame looks at that exact moment to see which buttons are pressed, where the mouse is, or how the controller is being used.
14
14
@@ -655,7 +655,7 @@ In the next chapter, we'll learn how to track previous input states to handle si
655
655
<details>
656
656
<summary>Question7Answer</summary>
657
657
658
-
>Touchinputcanhandlemultiplesimultaneoustouchpointsthroughthe [**TouchCollection**](Microsoft.Xna.Framework.Input.Touch.TouchCollection), whilemouseinputonlytracksasinglecursorposition. Thisallowstouchinputtosupportfeatureslikemulti-touchgesturesthataren't possible with a mouse.
658
+
>Touchinputcanhandlemultiplesimultaneoustouchpointsthroughthe [**TouchCollection**](xref:Microsoft.Xna.Framework.Input.Touch.TouchCollection), whilemouseinputonlytracksasinglecursorposition. Thisallowstouchinputtosupportfeatureslikemulti-touchgesturesthataren't possible with a mouse.
Recall from the [previous chapter](../09_handling_input/index.md#gamepad-input) that a [**PlayerIndex**](xref:Microsoft.Xna.Framework.PlayerIndex) value needs to be supplied when calling [**Gamepad.GetState**](xref:Microsoft.Xna.Framework.Input.GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex)). Doing this returns the state of the gamepad connected at that player index. So we'll need a property to track the player index this gamepad info is for.
593
+
Recall from the [previous chapter](../11_handling_input/index.md#gamepad-input) that a [**PlayerIndex**](xref:Microsoft.Xna.Framework.PlayerIndex) value needs to be supplied when calling [**Gamepad.GetState**](xref:Microsoft.Xna.Framework.Input.GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex)). Doing this returns the state of the gamepad connected at that player index. So we'll need a property to track the player index this gamepad info is for.
594
594
595
595
```cs
596
596
/// <summary>
@@ -904,9 +904,9 @@ Now that we have our input management system complete, let's update our game to
904
904
Components.Add(_input);
905
905
```
906
906
907
-
4. In [**Update**](xref:xref:Microsoft.Xna.Framework.Game.Update(Microsoft.Xna.Framework.GameTime)), removethe `if` statementthatchecksfor the gamepad back button or keyboard escape key being pressed and then calls exit. We're going to move this to the individual handle input methods in a moment.
907
+
4. In [**Update**](xref:Microsoft.Xna.Framework.Game.Update(Microsoft.Xna.Framework.GameTime)), removethe `if` statementthatchecksfor the gamepad back button or keyboard escape key being pressed and then calls exit. We're going to move this to the individual handle input methods in a moment.
908
908
909
-
5. In [**Update**](xref:xref:Microsoft.Xna.Framework.Game.Update(Microsoft.Xna.Framework.GameTime)) movethe `base.Update(gameTime)` callfrombeingthelastlineofthemethodtothefirstlineofthemethod. Wedothisbecausegamecomponentsareupdatedduringthe `base.Update(gameTime)` callandwewanttoensurethatinputisupdatedbeforewestarthandlinginputchecks.
909
+
5. In [**Update**](xref:Microsoft.Xna.Framework.Game.Update(Microsoft.Xna.Framework.GameTime)) movethe `base.Update(gameTime)` callfrombeingthelastlineofthemethodtothefirstlineofthemethod. Wedothisbecausegamecomponentsareupdatedduringthe `base.Update(gameTime)` callandwewanttoensurethatinputisupdatedbeforewestarthandlinginputchecks.
Sometimes, instead of preventing an object from moving onto another object, we want to ensure an object remains contained within a certain bounding area. MonoGame also provides the [**Rectangle.Contains**](xref:Microsoft.Xna.Framework.Rectangle.Contains(Microsoft.Xna.Framework.Rectangle)) method that we can use to determine this. [**Rectangle.Contains**](xref:Microsoft.Xna.Framework.Rectangle.Contains(Microsoft.Xna.Framework.Rectangle)) can check if any of the following are completely contained within the bounds of the rectangle;
For example, if we wanted to perform a blocking collision response that ensure a sprite remained contained within the bounds of the game screen:
@@ -401,7 +402,7 @@ For our simple game with just two objects, this optimization isn't necessary. Ho
401
402
402
403
## The Circle Struct
403
404
404
-
For our game, we are going to implement circle based collision detection. MonoGame does not have a `Circle` struct to represent a circle like it does with [**Rectangle**](xref:Microsoft.Xna.Framework.Rectangle). Before we can perform circle collision, we will need to create our own.
405
+
For our game, we are going to implement circle based collision detection. MonoGame does not have a `Circle` struct to represent a circle like it does with [**Rectangle**](xref:Microsoft.Xna.Framework.Rectangle). Before we can perform circle collision, we will need to create our own.
405
406
406
407
In the *MonoGameLibrary* project, add a new file named *Circle.cs*. Add the following code as the foundation of the `Circle` struct:
407
408
@@ -797,7 +798,7 @@ Running the game now, you'll see the bat moving automatically and bouncing off t
Finally, let's add a trigger response when the slime "eats" the bat, causing the bat to respawn at a random location on the screen with a new random velocity. In [**Update**](xref:xref:Microsoft.Xna.Framework.Game.Update(Microsoft.Xna.Framework.GameTime)) after we set the new position for the bat, add the following
801
+
Finally, let's add a trigger response when the slime "eats" the bat, causing the bat to respawn at a random location on the screen with a new random velocity. In [**Update**](xref:Microsoft.Xna.Framework.Game.Update(Microsoft.Xna.Framework.GameTime)) after we set the new position for the bat, add the following
801
802
802
803
```cs
803
804
if (slimeBounds.Intersects(batBounds))
@@ -909,4 +910,4 @@ In the next chapter, we'll start exploring audio to add sound effects when a col
909
910
<summary>Question 6 Answer</summary>
910
911
911
912
> We store the previous position so that if a collision occurs after movement, we can reset the object back to its last valid position. This prevents objects from moving through each other by undoing any movement that would cause overlap.
Copy file name to clipboardExpand all lines: articles/tutorials/building_2d_games/14_soundeffects_and_music/index.md
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -60,7 +60,7 @@ The key characteristics of sound effects are:
60
60
61
61
### Music
62
62
63
-
The [**Song**](xref:Microsoft.Xna.Framework.Audio.Song) class handles longer audio pieces like background music. The key characteristics of songs are:
63
+
The [**Song**](xref:Microsoft.Xna.Framework.Media.Song) class handles longer audio pieces like background music. The key characteristics of songs are:
64
64
65
65
- Streamed from storage rather than loaded into memory.
66
66
- Only one song can be played at a time.
@@ -91,7 +91,7 @@ Adding audio files can be done through the content pipeline, just like we did fo
91
91
The processor that are available for audio files file:
92
92
93
93
-**Sound Effects**: Processes the audio file as a [**SoundEffect**](xref:Microsoft.Xna.Framework.Audio.SoundEffect). This is automatically selected for *.wav* files.
94
-
-**Soung**: Processes the audio file as a [**Song**](xref:Microsoft.Xna.Framework.Audio.Song). This is automatically selected for *.mp3*, *.ogg*, and *.wma* files.
94
+
-**Soung**: Processes the audio file as a [**Song**](xref:Microsoft.Xna.Framework.Media.Song). This is automatically selected for *.mp3*, *.ogg*, and *.wma* files.
95
95
96
96
|||
> While [**SoundEffect**](xref:Microsoft.Xna.Framework.Audio.SoundEffect) instances can be played simultaneously, trying to play a new [**Song**](xref:Microsoft.Xna.Framework.Audio.Song) while another is playing will stop the current song in the best case, and in the worst case cause a crash on some platforms. In the example above, the state of the media player is checked first before we tell it to play a song. Checking the state first and stopping it manually if it is playing is best practice to prevent potential crashes.
185
+
> While [**SoundEffect**](xref:Microsoft.Xna.Framework.Audio.SoundEffect) instances can be played simultaneously, trying to play a new [**Song**](xref:Microsoft.Xna.Framework.Media.Song) while another is playing will stop the current song in the best case, and in the worst case cause a crash on some platforms. In the example above, the state of the media player is checked first before we tell it to play a song. Checking the state first and stopping it manually if it is playing is best practice to prevent potential crashes.
0 commit comments