From efda45e76c38a2d38a4cd0bb66ece9792f5832df Mon Sep 17 00:00:00 2001 From: oloshe <40467840+oloshe@users.noreply.github.com> Date: Wed, 27 Apr 2022 00:00:56 +0800 Subject: [PATCH] fix: correctly calculating frame length (#1578) --- packages/flame/lib/src/sprite_animation.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/flame/lib/src/sprite_animation.dart b/packages/flame/lib/src/sprite_animation.dart index f4ed3cac47f..d58712317e0 100644 --- a/packages/flame/lib/src/sprite_animation.dart +++ b/packages/flame/lib/src/sprite_animation.dart @@ -84,17 +84,17 @@ class SpriteAnimationData { this.loop = true, }) : assert(amountPerRow == null || amount >= amountPerRow), assert(start <= end && start >= 0 && end <= amount), - assert(stepTimes.length == end - start) { + assert(stepTimes.length >= end - start + 1) { amountPerRow ??= amount; texturePosition ??= Vector2.zero(); - frames = List.generate(end - start, (index) { + frames = List.generate(end - start + 1, (index) { final i = index + start; final position = Vector2( texturePosition!.x + (i % amountPerRow!) * textureSize.x, texturePosition.y + (i ~/ amountPerRow) * textureSize.y, ); return SpriteAnimationFrameData( - stepTime: stepTimes[i], + stepTime: stepTimes[index], srcPosition: position, srcSize: textureSize, );