refactor: defined DinoWalls sprites

pull/158/head
alestiago 4 years ago
parent 2b5636e652
commit f1e4330fac

@ -81,13 +81,10 @@ class _DinoTopWall extends BodyComponent with InitialPosition {
@override @override
Body createBody() { Body createBody() {
renderBody = false;
final bodyDef = BodyDef() final bodyDef = BodyDef()
..userData = this ..userData = this
..position = initialPosition ..position = initialPosition
..type = BodyType.static; ..type = BodyType.static;
final body = world.createBody(bodyDef); final body = world.createBody(bodyDef);
_createFixtureDefs().forEach( _createFixtureDefs().forEach(
(fixture) => body.createFixture( (fixture) => body.createFixture(
@ -103,21 +100,22 @@ class _DinoTopWall extends BodyComponent with InitialPosition {
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
await _loadSprite(); renderBody = false;
await add(_DinoTopWallSprite());
} }
}
Future<void> _loadSprite() async { class _DinoTopWallSprite extends SpriteComponent with HasGameRef {
@override
Future<void> onLoad() async {
await super.onLoad();
final sprite = await gameRef.loadSprite( final sprite = await gameRef.loadSprite(
Assets.images.dino.dinoLandTop.keyName, Assets.images.dino.dinoLandTop.keyName,
); );
final spriteComponent = SpriteComponent( this.sprite = sprite;
sprite: sprite, size = sprite.originalSize / 10;
size: Vector2(10.6, 27.7), position = Vector2(27, -28.2);
anchor: Anchor.center,
position: Vector2(27, -28.2),
);
await add(spriteComponent);
} }
} }
@ -182,8 +180,6 @@ class _DinoBottomWall extends BodyComponent with InitialPosition {
@override @override
Body createBody() { Body createBody() {
renderBody = false;
final bodyDef = BodyDef() final bodyDef = BodyDef()
..userData = this ..userData = this
..position = initialPosition ..position = initialPosition
@ -204,19 +200,21 @@ class _DinoBottomWall extends BodyComponent with InitialPosition {
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
await _loadSprite(); renderBody = false;
await add(_DinoBottomWallSprite());
} }
}
Future<void> _loadSprite() async { class _DinoBottomWallSprite extends SpriteComponent with HasGameRef {
@override
Future<void> onLoad() async {
await super.onLoad();
final sprite = await gameRef.loadSprite( final sprite = await gameRef.loadSprite(
Assets.images.dino.dinoLandBottom.keyName, Assets.images.dino.dinoLandBottom.keyName,
); );
final spriteComponent = SpriteComponent( this.sprite = sprite;
sprite: sprite, size = sprite.originalSize / 10;
size: Vector2(15.6, 54.8), position = Vector2(31.7, 18);
anchor: Anchor.center,
)..position = Vector2(31.7, 18);
await add(spriteComponent);
} }
} }

Loading…
Cancel
Save