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, );