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/09_handling_input/index.md
+40-4Lines changed: 40 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -563,20 +563,20 @@ In the next chapter, we'll learn how to track previous input states to handle si
563
563
564
564
## Test Your Knowledge
565
565
566
-
1. Why do we store the result of GetState() in a variable instead of calling it multiple times?
566
+
1. Why do we store the result of `GetState` in a variable instead of calling it multiple times?
567
567
568
568
<details>
569
569
<summary>Question 1 Answer</summary>
570
570
571
-
> Storing the state in a variable is more efficient and ensures consistent input checking within a frame. Each GetState() call polls the device, which can impact performance if called repeatedly.
571
+
> Storing the state in a variable is more efficient and ensures consistent input checking within a frame. Each `GetState` call polls the device, which can impact performance if called repeatedly.
572
572
</details><br />
573
573
574
574
2. What's the main difference between how keyboard and mouse/gamepad button states are checked?
575
575
576
576
<details>
577
577
<summary>Question 2 Answer</summary>
578
578
579
-
> Keyboard input uses IsKeyUp/IsKeyDown methods, while mouse and gamepad buttons return a ButtonState enum value (Pressed or Released).
579
+
> Keyboard input uses [**IsKeyUp**](xref:Microsoft.Xna.Framework.Input.KeyboardState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys))/[**IsKeyDown**](xref:Microsoft.Xna.Framework.Input.KeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys)) methods, while mouse and gamepad buttons return a [**ButtonState**](xref:Microsoft.Xna.Framework.Input.ButtonState) enum value (Pressed or Released).
580
580
</details><br />
581
581
582
582
3. When using thumbstick values for movement, why do we multiply the Y value by -1?
@@ -593,4 +593,40 @@ In the next chapter, we'll learn how to track previous input states to handle si
593
593
<summary>Question 4 Answer</summary>
594
594
595
595
> Analog triggers provide values between 0.0f and 1.0f based on how far they're pressed, while digital triggers only report 0.0f (not pressed) or 1.0f (pressed). This affects how you handle trigger input in your game.
596
-
</details><br />
596
+
</details><br />
597
+
598
+
5. What's the key difference between [**TouchPanel.GetState**](xref:Microsoft.Xna.Framework.Input.Touch.TouchPanel.GetState) and [**TouchPanel.ReadGesture**](xref:Microsoft.Xna.Framework.Input.Touch.TouchPanel.ReadGesture)?
599
+
600
+
<details>
601
+
<summary>Question 5 Answer</summary>
602
+
603
+
> [**TouchPanel.GetState**](xref:Microsoft.Xna.Framework.Input.Touch.TouchPanel.GetState) returns information about current touch points on the screen, while [**TouchPanel.ReadGesture**](xref:Microsoft.Xna.Framework.Input.Touch.TouchPanel.ReadGesture) provides information about specific gesture patterns like taps, drags, and pinches that have been performed.
604
+
</details><br />
605
+
606
+
6. Why do we use a while loop with [**TouchPanel.IsGestureAvailable**](xref:Microsoft.Xna.Framework.Input.Touch.TouchPanel.IsGestureAvailable) when reading gestures?
607
+
608
+
<details>
609
+
<summary>Question 6 Answer</summary>
610
+
611
+
> Quick gestures can generate multiple gesture events that are queued. Using a while loop with [**TouchPanel.IsGestureAvailable**](xref:Microsoft.Xna.Framework.Input.Touch.TouchPanel.IsGestureAvailable) ensures we process all queued gestures, as [**TouchPanel.ReadGesture**](xref:Microsoft.Xna.Framework.Input.Touch.TouchPanel.ReadGesture) only returns one gesture at a time.
612
+
</details><br />
613
+
614
+
7. How does touch input differ from mouse input in terms of handling multiple input points?
615
+
616
+
<details>
617
+
<summary>Question 7 Answer</summary>
618
+
619
+
> Touch input can handle multiple simultaneous touch points through the [**TouchCollection**](Microsoft.Xna.Framework.Input.Touch.TouchCollection), while mouse input only tracks a single cursor position. This allows touch input to support features like multi-touch gestures that aren't possible with a mouse.
620
+
</details><br />
621
+
622
+
8. What are the different states a [**TouchLocation**](xref:Microsoft.Xna.Framework.Input.Touch.TouchLocation) can have and what do they indicate?
623
+
624
+
<details>
625
+
<summary>Question 8 Answer</summary>
626
+
627
+
> A [**TouchLocation**](xref:Microsoft.Xna.Framework.Input.Touch.TouchLocation) can have four states:
628
+
> -[**Pressed**](xref:Microsoft.Xna.Framework.Input.Touch.TouchLocationState): Initial contact with the screen
629
+
> -[**Moved**](xref:Microsoft.Xna.Framework.Input.Touch.TouchLocationState): Touch point moved while maintaining contact
630
+
> -[**Released**](xref:Microsoft.Xna.Framework.Input.Touch.TouchLocationState): Contact with the screen ended
631
+
> -[**Invalid**](xref:Microsoft.Xna.Framework.Input.Touch.TouchLocationState): Touch data is not valid or tracking was lost
0 commit comments