Files
flame/lib/components/animation_component.dart
2018-03-04 18:46:59 -03:00

39 lines
1015 B
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.sequenced(width, height, String imagePath, int amount, { double textureX = 0.0, double textureY = 0.0, double textureWidth = -1.0, double textureHeight = -1.0}) {
this.width = width;
this.height = height;
this.animation = new Animation.sequenced(imagePath, amount, textureX: textureX, textureY: textureY, textureWidth: textureWidth, textureHeight: textureHeight);
}
@override
bool loaded() {
return this.animation.loaded();
}
@override
void render(Canvas canvas) {
if (loaded() && x != null && y != null) {
prepareCanvas(canvas);
animation.getSprite().render(canvas, width, height);
}
}
@override
void update(double t) {
animation.update(t);
}
}