refactor: load sprite method

pull/131/head
Allison Ryan 4 years ago
parent ad36abffca
commit 4a2f82d4a1

@ -51,10 +51,23 @@ class _BottomBoundary extends BodyComponent with InitialPosition {
return fixturesDefs; return fixturesDefs;
} }
@override
Body createBody() {
final bodyDef = BodyDef()..position = initialPosition;
final body = world.createBody(bodyDef);
_createFixtureDefs().forEach(body.createFixture);
return body;
}
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
await _loadSprite();
renderBody = false;
}
Future<void> _loadSprite() async {
final sprite = await gameRef.loadSprite( final sprite = await gameRef.loadSprite(
Assets.images.boundary.bottom.keyName, Assets.images.boundary.bottom.keyName,
); );
@ -62,22 +75,11 @@ class _BottomBoundary extends BodyComponent with InitialPosition {
await add( await add(
SpriteComponent( SpriteComponent(
sprite: sprite, sprite: sprite,
size: Vector2(96.7, 29.1), size: sprite.originalSize / 10,
anchor: Anchor.center, anchor: Anchor.center,
position: Vector2(-5.4, 57.4), position: Vector2(-5.4, 57.4),
), ),
); );
renderBody = false;
}
@override
Body createBody() {
final bodyDef = BodyDef()..position = initialPosition;
final body = world.createBody(bodyDef);
_createFixtureDefs().forEach(body.createFixture);
return body;
} }
} }
@ -121,10 +123,23 @@ class _OuterBoundary extends BodyComponent with InitialPosition {
return fixturesDefs; return fixturesDefs;
} }
@override
Body createBody() {
final bodyDef = BodyDef()..position = initialPosition;
final body = world.createBody(bodyDef);
_createFixtureDefs().forEach(body.createFixture);
return body;
}
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
await _loadSprite();
renderBody = false;
}
Future<void> _loadSprite() async {
final sprite = await gameRef.loadSprite( final sprite = await gameRef.loadSprite(
Assets.images.boundary.outer.keyName, Assets.images.boundary.outer.keyName,
); );
@ -132,21 +147,10 @@ class _OuterBoundary extends BodyComponent with InitialPosition {
await add( await add(
SpriteComponent( SpriteComponent(
sprite: sprite, sprite: sprite,
size: Vector2(105.1, 146.7), size: sprite.originalSize / 10,
anchor: Anchor.center, anchor: Anchor.center,
position: Vector2(-0.2, -1.4), position: Vector2(-0.2, -1.4),
), ),
); );
renderBody = false;
}
@override
Body createBody() {
final bodyDef = BodyDef()..position = initialPosition;
final body = world.createBody(bodyDef);
_createFixtureDefs().forEach(body.createFixture);
return body;
} }
} }

Loading…
Cancel
Save