mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 00:31:34 +11:00
Start section on controls
This commit is contained in:
parent
2705c58a72
commit
e666ebbd05
|
@ -11,3 +11,4 @@
|
||||||
- [Learn agb part I - pong](./pong/01_introduction.md)
|
- [Learn agb part I - pong](./pong/01_introduction.md)
|
||||||
- [The Gba struct](./pong/02_the_gba_struct.md)
|
- [The Gba struct](./pong/02_the_gba_struct.md)
|
||||||
- [Sprites](./pong/03_sprites.md)
|
- [Sprites](./pong/03_sprites.md)
|
||||||
|
- [Controls](./pong/04_controls.md)
|
||||||
|
|
23
book/src/pong/04_controls.md
Normal file
23
book/src/pong/04_controls.md
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# Controls
|
||||||
|
|
||||||
|
In this section, we'll make the ball that we displayed in the last section move by pressing the D-Pad.
|
||||||
|
|
||||||
|
# The GBA controls
|
||||||
|
|
||||||
|
The GBA has 10 buttons we can read the state of, and this is the only way a player can directly control the game.
|
||||||
|
They are the 4 directions on the D-Pad, A, B, Start, Select, and the L and R triggers.
|
||||||
|
|
||||||
|
# Reading the button state
|
||||||
|
|
||||||
|
There are two ways to capture the button state in **agb**, interrupts and polling.
|
||||||
|
In most games, you will want to use polling, so that is what we will use now.
|
||||||
|
Interrupts will be covered in a later chapter.
|
||||||
|
|
||||||
|
To add button control to our game, we will need a [ButtonController](https://docs.rs/agb/latest/agb/input/struct.ButtonController.html).
|
||||||
|
Add this near the top of your main function:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
let mut input = agb::input::ButtonController::new();
|
||||||
|
```
|
||||||
|
|
||||||
|
The button controller is not part of the `Gba` struct because it only allows for reading and not writing so does not need to be controlled by the borrow checker.
|
Loading…
Reference in a new issue