diff --git a/src/animation.rs b/src/animation.rs index cf7016a..b3871e0 100644 --- a/src/animation.rs +++ b/src/animation.rs @@ -83,7 +83,24 @@ impl<'a> AnimatedTexture<'a> { self.render_static(canvas, position, direction, Some(self.current_frame())); self.tick(); } + + // Functions like render, but only ticks the animation until the given frame is reached. + pub fn render_until( + &mut self, + canvas: &mut Canvas, + position: (i32, i32), + direction: Direction, + frame: u32, + ) { + let current = self.current_frame(); + self.render_static(canvas, position, direction, Some(current)); + + if frame != current { + self.tick(); + } + } + // Renders a specific frame of the animation. Defaults to the current frame. pub fn render_static( &mut self, canvas: &mut Canvas, diff --git a/src/pacman.rs b/src/pacman.rs index 2cddfc5..d9fcb42 100644 --- a/src/pacman.rs +++ b/src/pacman.rs @@ -34,6 +34,11 @@ impl Pacman<'_> { } pub fn render(&mut self, canvas: &mut Canvas) { + // When stopped, render the last frame of the animation + if self.stopped { + self.sprite + .render_until(canvas, self.position, self.direction, 2); + } else { self.sprite.render(canvas, self.position, self.direction); }