From 7ec7ffc9b3e9775fb9f2df34c27377a694e5567b Mon Sep 17 00:00:00 2001 From: alestiago Date: Thu, 7 Apr 2022 11:44:52 +0100 Subject: [PATCH] refactor: defined _AndroidHeadSpriteAnimation --- .../lib/src/components/spaceship.dart | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/packages/pinball_components/lib/src/components/spaceship.dart b/packages/pinball_components/lib/src/components/spaceship.dart index f1b58db0..ccb86b07 100644 --- a/packages/pinball_components/lib/src/components/spaceship.dart +++ b/packages/pinball_components/lib/src/components/spaceship.dart @@ -102,27 +102,9 @@ class AndroidHead extends BodyComponent with InitialPosition, Layered { @override Future onLoad() async { await super.onLoad(); - renderBody = false; - final sprite = await gameRef.images.load( - Assets.images.spaceship.bridge.keyName, - ); - - await add( - SpriteAnimationComponent.fromFrameData( - sprite, - SpriteAnimationData.sequenced( - amount: 72, - amountPerRow: 24, - stepTime: 0.05, - textureSize: Vector2(82, 100), - ), - size: Vector2(8.2, 10), - position: Vector2(0, -2), - anchor: Anchor.center, - ), - ); + await add(_AndroidHeadSpriteAnimation()); } @override @@ -141,6 +123,29 @@ class AndroidHead extends BodyComponent with InitialPosition, Layered { } } +class _AndroidHeadSpriteAnimation extends SpriteAnimationComponent + with HasGameRef { + @override + Future onLoad() async { + await super.onLoad(); + + final image = await gameRef.images.load( + Assets.images.spaceship.bridge.keyName, + ); + size = Vector2(8.2, 10); + position = Vector2(0, -2); + anchor = Anchor.center; + + final data = SpriteAnimationData.sequenced( + amount: 72, + amountPerRow: 24, + stepTime: 0.05, + textureSize: size * 10, + ); + animation = SpriteAnimation.fromFrameData(image, data); + } +} + /// {@template spaceship_entrance} /// A sensor [BodyComponent] used to detect when the ball enters the /// the spaceship area in order to modify its filter data so the ball