mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 10:38:17 +08:00
57 lines
1.2 KiB
Dart
57 lines
1.2 KiB
Dart
import 'dart:ui';
|
|
|
|
import 'component.dart';
|
|
import 'package:flame/flare_animation.dart';
|
|
|
|
class FlareComponent extends PositionComponent {
|
|
FlareAnimation _flareAnimation;
|
|
|
|
FlareComponent(
|
|
String fileName, String animation, double width, double height) {
|
|
this.width = width;
|
|
this.height = height;
|
|
|
|
FlareAnimation.load(fileName).then((loadedFlareAnimation) {
|
|
_flareAnimation = loadedFlareAnimation;
|
|
|
|
_flareAnimation.updateAnimation(animation);
|
|
_flareAnimation.width = width;
|
|
_flareAnimation.height = height;
|
|
});
|
|
}
|
|
|
|
void updateAnimation(String animation) {
|
|
if (loaded()) {
|
|
_flareAnimation.updateAnimation(animation);
|
|
}
|
|
}
|
|
|
|
@override
|
|
bool loaded() => _flareAnimation != null;
|
|
|
|
@override
|
|
void render(Canvas canvas) {
|
|
prepareCanvas(canvas);
|
|
_flareAnimation.render(canvas, x: 0, y: 0);
|
|
}
|
|
|
|
@override
|
|
void update(double dt) {
|
|
if (loaded()) {
|
|
_flareAnimation.update(dt);
|
|
}
|
|
}
|
|
|
|
@override
|
|
set width(_width) {
|
|
super.width = _width;
|
|
if (loaded()) _flareAnimation.width = width;
|
|
}
|
|
|
|
@override
|
|
set height(_height) {
|
|
super.height = _height;
|
|
if (loaded()) _flareAnimation.height = height;
|
|
}
|
|
}
|