refactor: defined FlutterSIgnPostSprite

pull/158/head
alestiago 4 years ago
parent f1e4330fac
commit 585a753c1a

@ -4,30 +4,15 @@ import 'package:flutter/material.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
/// {@template flutter_sign_post} /// {@template flutter_sign_post}
/// A sign, found in the FlutterForest. /// A sign, found in the Flutter Forest.
/// {@endtemplate} /// {@endtemplate}
// TODO(alestiago): Revisit doc comment if FlutterForest is moved to package.
class FlutterSignPost extends BodyComponent with InitialPosition { class FlutterSignPost extends BodyComponent with InitialPosition {
Future<void> _loadSprite() async {
final sprite = await gameRef.loadSprite(
Assets.images.flutterSignPost.keyName,
);
final spriteComponent = SpriteComponent(
sprite: sprite,
size: sprite.originalSize / 10,
anchor: Anchor.bottomCenter,
position: Vector2(0.65, 0.45),
);
await add(spriteComponent);
}
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
paint = Paint() renderBody = false;
..color = Colors.blue.withOpacity(0.5)
..style = PaintingStyle.fill; await add(_FlutterSignPostSprite());
await _loadSprite();
} }
@override @override
@ -39,3 +24,18 @@ class FlutterSignPost extends BodyComponent with InitialPosition {
return world.createBody(bodyDef)..createFixture(fixtureDef); return world.createBody(bodyDef)..createFixture(fixtureDef);
} }
} }
class _FlutterSignPostSprite extends SpriteComponent with HasGameRef {
@override
Future<void> onLoad() async {
await super.onLoad();
final sprite = await gameRef.loadSprite(
Assets.images.flutterSignPost.keyName,
);
this.sprite = sprite;
size = sprite.originalSize / 10;
anchor = Anchor.bottomCenter;
position = Vector2(0.65, 0.45);
}
}

Loading…
Cancel
Save