fix: correctly calculating frame length (#1578)

This commit is contained in:
oloshe
2022-04-27 00:00:56 +08:00
committed by GitHub
parent 8e81261def
commit efda45e76c

View File

@@ -84,17 +84,17 @@ class SpriteAnimationData {
this.loop = true, this.loop = true,
}) : assert(amountPerRow == null || amount >= amountPerRow), }) : assert(amountPerRow == null || amount >= amountPerRow),
assert(start <= end && start >= 0 && end <= amount), assert(start <= end && start >= 0 && end <= amount),
assert(stepTimes.length == end - start) { assert(stepTimes.length >= end - start + 1) {
amountPerRow ??= amount; amountPerRow ??= amount;
texturePosition ??= Vector2.zero(); texturePosition ??= Vector2.zero();
frames = List<SpriteAnimationFrameData>.generate(end - start, (index) { frames = List<SpriteAnimationFrameData>.generate(end - start + 1, (index) {
final i = index + start; final i = index + start;
final position = Vector2( final position = Vector2(
texturePosition!.x + (i % amountPerRow!) * textureSize.x, texturePosition!.x + (i % amountPerRow!) * textureSize.x,
texturePosition.y + (i ~/ amountPerRow) * textureSize.y, texturePosition.y + (i ~/ amountPerRow) * textureSize.y,
); );
return SpriteAnimationFrameData( return SpriteAnimationFrameData(
stepTime: stepTimes[i], stepTime: stepTimes[index],
srcPosition: position, srcPosition: position,
srcSize: textureSize, srcSize: textureSize,
); );