feat: defined BallSprite

pull/158/head
alestiago 4 years ago
parent 3ac0df99b2
commit 2ec521451d

@ -35,23 +35,18 @@ class Ball<T extends Forge2DGame> extends BodyComponent<T>
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
final sprite = await gameRef.loadSprite(Assets.images.ball.keyName);
final tint = baseColor.withOpacity(0.5);
await add( await add(
_spriteComponent = SpriteComponent( _BallSprite()
sprite: sprite, ..tint(
size: size * 1.15, baseColor.withOpacity(0.5),
anchor: Anchor.center, ),
)..tint(tint),
); );
} }
@override @override
Body createBody() { Body createBody() {
final shape = CircleShape()..radius = size.x / 2; final shape = CircleShape()..radius = size.x / 2;
final fixtureDef = FixtureDef(shape)..density = 1; final fixtureDef = FixtureDef(shape)..density = 1;
final bodyDef = BodyDef() final bodyDef = BodyDef()
..position = initialPosition ..position = initialPosition
..userData = this ..userData = this
@ -114,3 +109,17 @@ class Ball<T extends Forge2DGame> extends BodyComponent<T>
_spriteComponent.scale = Vector2.all(scaleFactor); _spriteComponent.scale = Vector2.all(scaleFactor);
} }
} }
class _BallSprite extends SpriteComponent with HasGameRef {
@override
Future<void> onLoad() async {
await super.onLoad();
final sprite = await gameRef.loadSprite(
Assets.images.ball.keyName,
);
this.sprite = sprite;
size = Ball.size * 1.15;
anchor = Anchor.center;
}
}

Loading…
Cancel
Save