mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-14 11:51:21 +08:00
fix: correctly calculating frame length (#1578)
This commit is contained in:
@@ -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,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user