Skip to content

Commit

Permalink
fix: AnchoredAnimationGroup positioning breaks when children change s…
Browse files Browse the repository at this point in the history
…prite offset during update
  • Loading branch information
kurtome committed Sep 16, 2024
1 parent 496762b commit a1b01fa
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/leap/lib/src/entities/anchored_animation_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import 'package:flutter/foundation.dart';
/// [animations] should be set in [onLoad] if they require asset loading.
/// It is also possible to use this without a subclass by simply setting
/// the [current] value in the parent's [update].
class AnchoredAnimationGroup<TKey, TChar extends PositionedEntity>
extends SpriteAnimationGroupComponent<TKey> with ParentIsA<TChar> {
class AnchoredAnimationGroup<TKey, TParent extends PositionComponent>
extends SpriteAnimationGroupComponent<TKey> with ParentIsA<TParent> {
AnchoredAnimationGroup({
this.spriteAnchor = Anchor.bottomCenter,
Vector2? spriteOffset,
Expand Down Expand Up @@ -49,9 +49,16 @@ class AnchoredAnimationGroup<TKey, TChar extends PositionedEntity>
/// Adds an additional offset after the anchored positioning
late Vector2 spriteOffset;

/// Whether or not the current animation is done.
bool get animationDone => animationTicker?.done() ?? false;

@override
@mustCallSuper
void update(double dt) {
void updateTree(double dt) {
// The x, y calculations should happen after any children update the
// anchor and offset.
super.updateTree(dt);

if (parent.anchor != Anchor.topLeft) {
throw Exception(
'Parent must have topLeft anchor instead of ${parent.anchor}.',
Expand All @@ -73,7 +80,5 @@ class AnchoredAnimationGroup<TKey, TChar extends PositionedEntity>
// apply the offset after the normal calculations
x += spriteOffset.x;
y += spriteOffset.y;

super.update(dt);
}
}

0 comments on commit a1b01fa

Please sign in to comment.