Fixing example and restoring SpriteComponent

This commit is contained in:
Erick Zanardo
2020-07-02 19:41:37 -03:00
parent cdbd93c019
commit 67a694087e
5 changed files with 37 additions and 16 deletions

View File

@ -171,3 +171,36 @@ abstract class PositionComponent extends Component {
_effects.removeWhere((e) => e.hasFinished());
}
}
/// A [PositionComponent] that renders a single [Sprite] at the designated position, scaled to have the designated size and rotated to the designated angle.
///
/// This is the most commonly used child of [Component].
class SpriteComponent extends PositionComponent {
Sprite sprite;
Paint overridePaint;
SpriteComponent();
SpriteComponent.square(double size, String imagePath)
: this.rectangle(size, size, imagePath);
SpriteComponent.rectangle(double width, double height, String imagePath)
: this.fromSprite(width, height, Sprite(imagePath));
SpriteComponent.fromSprite(double width, double height, this.sprite) {
this.width = width;
this.height = height;
}
@override
void render(Canvas canvas) {
prepareCanvas(canvas);
sprite.render(canvas,
width: width, height: height, overridePaint: overridePaint);
}
@override
bool loaded() {
return sprite != null && sprite.loaded() && x != null && y != null;
}
}