From 95c0d99e45c0fecbd6d15bc334cf561bbffc0430 Mon Sep 17 00:00:00 2001 From: Alejandro Pascual Date: Sun, 11 Dec 2022 18:22:10 +0000 Subject: [PATCH] Sprite sheet example: specify animation indices (#6861) # Objective - Make running animation fluid skipping 'idle' frame. ## Solution - Loop through the specified indices instead of through the whole sprite sheet. The example is correct, is just the feeling that the animation loop is not seamless. Based on the solution suggested by @mockersf in #5429. --- examples/2d/sprite_sheet.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/examples/2d/sprite_sheet.rs b/examples/2d/sprite_sheet.rs index 569821db7c..597737bdb3 100644 --- a/examples/2d/sprite_sheet.rs +++ b/examples/2d/sprite_sheet.rs @@ -11,23 +11,31 @@ fn main() { .run(); } +#[derive(Component)] +struct AnimationIndices { + first: usize, + last: usize, +} + #[derive(Component, Deref, DerefMut)] struct AnimationTimer(Timer); fn animate_sprite( time: Res