Skip to content

Commit 8747fb7

Browse files
committed
Additional questions
1 parent 6531438 commit 8747fb7

File tree

1 file changed

+40
-4
lines changed
  • articles/tutorials/building_2d_games/09_handling_input

1 file changed

+40
-4
lines changed

articles/tutorials/building_2d_games/09_handling_input/index.md

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -563,20 +563,20 @@ In the next chapter, we'll learn how to track previous input states to handle si
563563

564564
## Test Your Knowledge
565565

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?
567567

568568
<details>
569569
<summary>Question 1 Answer</summary>
570570

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.
572572
</details><br />
573573
574574
2. What's the main difference between how keyboard and mouse/gamepad button states are checked?
575575

576576
<details>
577577
<summary>Question 2 Answer</summary>
578578

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).
580580
</details><br />
581581
582582
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
593593
<summary>Question 4 Answer</summary>
594594

595595
> 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
632+
</details><br />

0 commit comments

Comments
 (0)