mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-03 04:18:25 +08:00
70 lines
1.3 KiB
Dart
70 lines
1.3 KiB
Dart
import 'dart:ui';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import '../flare_animation.dart';
|
|
import 'position_component.dart';
|
|
|
|
@Deprecated("Use flame_flare package instead")
|
|
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;
|
|
|
|
@mustCallSuper
|
|
@override
|
|
void render(Canvas canvas) {
|
|
super.render(canvas);
|
|
_flareAnimation.render(canvas, x: 0, y: 0);
|
|
}
|
|
|
|
@override
|
|
void update(double dt) {
|
|
super.update(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;
|
|
}
|
|
}
|
|
}
|