refactor: remove _loadSprites

pull/158/head
alestiago 4 years ago
parent 1a8f534ece
commit 3ac0df99b2

@ -63,23 +63,22 @@ class _BottomBoundary extends BodyComponent with InitialPosition {
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
await _loadSprite();
renderBody = false; renderBody = false;
await add(_BottomBoundarySprite());
} }
}
Future<void> _loadSprite() async { class _BottomBoundarySprite extends SpriteComponent with HasGameRef {
@override
Future<void> onLoad() async {
await super.onLoad();
final sprite = await gameRef.loadSprite( final sprite = await gameRef.loadSprite(
Assets.images.boundary.bottom.keyName, Assets.images.boundary.bottom.keyName,
); );
this.sprite = sprite;
await add( size = sprite.originalSize / 10;
SpriteComponent( anchor = Anchor.center;
sprite: sprite, position = Vector2(-5.4, 57.4);
size: sprite.originalSize / 10,
anchor: Anchor.center,
position: Vector2(-5.4, 57.4),
),
);
} }
} }
@ -135,22 +134,21 @@ class _OuterBoundary extends BodyComponent with InitialPosition {
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
await _loadSprite();
renderBody = false; renderBody = false;
await add(_OuterBoundarySprite());
} }
}
Future<void> _loadSprite() async { class _OuterBoundarySprite extends SpriteComponent with HasGameRef {
@override
Future<void> onLoad() async {
await super.onLoad();
final sprite = await gameRef.loadSprite( final sprite = await gameRef.loadSprite(
Assets.images.boundary.outer.keyName, Assets.images.boundary.outer.keyName,
); );
this.sprite = sprite;
await add( size = sprite.originalSize / 10;
SpriteComponent( anchor = Anchor.center;
sprite: sprite, position = Vector2(-0.2, -1.4);
size: sprite.originalSize / 10,
anchor: Anchor.center,
position: Vector2(-0.2, -1.4),
),
);
} }
} }

@ -96,8 +96,6 @@ class _SpaceshipRampBackground extends BodyComponent
@override @override
Body createBody() { Body createBody() {
renderBody = false;
final bodyDef = BodyDef() final bodyDef = BodyDef()
..userData = this ..userData = this
..position = initialPosition; ..position = initialPosition;
@ -111,35 +109,40 @@ class _SpaceshipRampBackground extends BodyComponent
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
await _loadSprites(); renderBody = false;
}
Future<void> _loadSprites() async {
final spriteRamp = await gameRef.loadSprite(
Assets.images.spaceship.ramp.main.keyName,
);
final spriteRampComponent = SpriteComponent( await add(_SpaceshipRampBackgroundRailingSprite());
sprite: spriteRamp, await add(_SpaceshipRampBackgroundRampSprite());
size: Vector2(38.1, 33.8), }
anchor: Anchor.center, }
position: Vector2(-12.2, -53.5),
);
final spriteRailingBg = await gameRef.loadSprite( class _SpaceshipRampBackgroundRailingSprite extends SpriteComponent
with HasGameRef {
@override
Future<void> onLoad() async {
await super.onLoad();
final sprite = await gameRef.loadSprite(
Assets.images.spaceship.ramp.railingBackground.keyName, Assets.images.spaceship.ramp.railingBackground.keyName,
); );
final spriteRailingBgComponent = SpriteComponent( this.sprite = sprite;
sprite: spriteRailingBg, size = Vector2(38.3, 35.1);
size: Vector2(38.3, 35.1), anchor = Anchor.center;
anchor: Anchor.center, position = Vector2(-12.2, -54.5);
position: spriteRampComponent.position + Vector2(0, -1), }
); }
await addAll([ class _SpaceshipRampBackgroundRampSprite extends SpriteComponent
spriteRailingBgComponent, with HasGameRef {
spriteRampComponent, @override
]); Future<void> onLoad() async {
await super.onLoad();
final sprite = await gameRef.loadSprite(
Assets.images.spaceship.ramp.main.keyName,
);
this.sprite = sprite;
size = Vector2(38.3, 35.1);
anchor = Anchor.center;
position = Vector2(-12.2, -543.5);
} }
} }
@ -196,21 +199,22 @@ class _SpaceshipRampForegroundRailing extends BodyComponent
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
await _loadSprites(); await add(_SpaceshipRampForegroundRalingSprite());
} }
}
Future<void> _loadSprites() async { class _SpaceshipRampForegroundRalingSprite extends SpriteComponent
final spriteRailingFg = await gameRef.loadSprite( with HasGameRef {
@override
Future<void> onLoad() async {
await super.onLoad();
final sprite = await gameRef.loadSprite(
Assets.images.spaceship.ramp.railingForeground.keyName, Assets.images.spaceship.ramp.railingForeground.keyName,
); );
final spriteRailingFgComponent = SpriteComponent( this.sprite = sprite;
sprite: spriteRailingFg, size = Vector2(26.1, 28.3);
size: Vector2(26.1, 28.3), anchor = Anchor.center;
anchor: Anchor.center, position = Vector2(-12.2, -52.5);
position: Vector2(-12.2, -52.5),
);
await add(spriteRailingFgComponent);
} }
} }

Loading…
Cancel
Save