Improve default constructor for positioned components (#667)

This commit is contained in:
pedia
2021-02-24 00:27:17 +08:00
committed by GitHub
parent ec09ce0ce6
commit 9735cf5e08
11 changed files with 95 additions and 47 deletions

View File

@@ -24,14 +24,19 @@ class SpriteComponent extends PositionComponent {
Paint overridePaint;
/// Creates a component with an empty sprite which can be set later
SpriteComponent();
SpriteComponent({
Vector2 position,
Vector2 size,
this.sprite,
this.overridePaint,
}) : super(position: position, size: size);
SpriteComponent.fromImage(Vector2 size, Image image)
: this.fromSprite(size, Sprite(image));
SpriteComponent.fromSprite(Vector2 size, this.sprite) {
super.size.setFrom(size);
}
factory SpriteComponent.fromImage(
Vector2 size,
Image image, {
Vector2 position,
}) =>
SpriteComponent(size: size, sprite: Sprite(image), position: position);
@mustCallSuper
@override