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,
}) : 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<SpriteAnimationFrameData>.generate(end - start, (index) {
frames = List<SpriteAnimationFrameData>.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,
);