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. 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.