mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 03:15:43 +08:00
52 lines
1.0 KiB
Dart
52 lines
1.0 KiB
Dart
import 'dart:ui';
|
|
|
|
import 'component.dart';
|
|
import 'package:flame/animation.dart';
|
|
|
|
class AnimationComponent extends PositionComponent {
|
|
Animation animation;
|
|
|
|
AnimationComponent(double width, double height, this.animation) {
|
|
this.width = width;
|
|
this.height = height;
|
|
}
|
|
|
|
AnimationComponent.empty();
|
|
|
|
AnimationComponent.sequenced(
|
|
width,
|
|
height,
|
|
String imagePath,
|
|
int amount, {
|
|
double textureX = 0.0,
|
|
double textureY = 0.0,
|
|
double textureWidth = null,
|
|
double textureHeight = null,
|
|
}) {
|
|
this.width = width;
|
|
this.height = height;
|
|
this.animation = new Animation.sequenced(
|
|
imagePath,
|
|
amount,
|
|
textureX: textureX,
|
|
textureY: textureY,
|
|
textureWidth: textureWidth,
|
|
textureHeight: textureHeight,
|
|
);
|
|
}
|
|
|
|
@override
|
|
bool loaded() => animation.loaded();
|
|
|
|
@override
|
|
void render(Canvas canvas) {
|
|
prepareCanvas(canvas);
|
|
animation.getSprite().render(canvas, width, height);
|
|
}
|
|
|
|
@override
|
|
void update(double t) {
|
|
animation.update(t);
|
|
}
|
|
}
|