From 23832d5efd10d5be06a064a7c7402add11cb80fa Mon Sep 17 00:00:00 2001 From: Corwin Date: Mon, 2 Mar 2026 21:10:51 +0000 Subject: [PATCH 1/2] change animation frame to increment the frame idx --- agb/src/display/object/sprites/sprite.rs | 6 ++++-- book/games/platform/src/main.rs | 2 -- book/src/platformer/06_the_player.md | 2 -- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/agb/src/display/object/sprites/sprite.rs b/agb/src/display/object/sprites/sprite.rs index a05492b66..5df00487a 100644 --- a/agb/src/display/object/sprites/sprite.rs +++ b/agb/src/display/object/sprites/sprite.rs @@ -333,7 +333,7 @@ impl Tag { /// animating sprites efficiently. pub fn animation_frame(&self, idx: &mut usize, divider: u32) -> &'static Sprite { let divided = *idx >> divider; - let idx = match self.direction { + let frame = match self.direction { Direction::Forward => { if divided >= self.sprites.len() { *idx = 0; @@ -362,7 +362,9 @@ impl Tag { } }; - &self.sprites[idx] + *idx += 1; + + &self.sprites[frame] } #[doc(hidden)] diff --git a/book/games/platform/src/main.rs b/book/games/platform/src/main.rs index 6ee7bf25e..4f8111d9e 100644 --- a/book/games/platform/src/main.rs +++ b/book/games/platform/src/main.rs @@ -155,8 +155,6 @@ impl Player { } fn update_sprite(&mut self) { - self.frame += 1; - if self.velocity.x > num!(0.1) { self.flipped = false; } diff --git a/book/src/platformer/06_the_player.md b/book/src/platformer/06_the_player.md index 7a57ea59e..4c65d3460 100644 --- a/book/src/platformer/06_the_player.md +++ b/book/src/platformer/06_the_player.md @@ -161,8 +161,6 @@ We need to update the sprite based on the player's state: ```rust impl Player { fn update_sprite(&mut self) { - self.frame += 1; - // We need to keep track of the facing direction rather than // deriving it because the zero velocity case needs to keep // facing the same direction. From 092b5277eb5ef4c758f4c65a9a8a7a252d1f9e5f Mon Sep 17 00:00:00 2001 From: Corwin Date: Mon, 2 Mar 2026 21:13:42 +0000 Subject: [PATCH 2/2] add changelog entry for incrementing animation frame --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b78e9d8a5..bf99abc6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - You can now import [yal.cc](https://yal.cc/tools/pixel-font/) fonts directly from the json + png / aseprite file without having to go via ttf. +### Changed + +- `Tag::animation_frame` now increments the provided frame. + ## [0.23.1] - 2026/02/07 - Minor release to fix problems with publishing 0.23.0.