-
-
Notifications
You must be signed in to change notification settings - Fork 875
/
animation_component.dart
65 lines (56 loc) · 1.41 KB
/
animation_component.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import 'dart:ui';
import 'component.dart';
import 'package:flame/animation.dart';
class AnimationComponent extends PositionComponent {
Animation animation;
Paint overridePaint;
bool destroyOnFinish = false;
AnimationComponent(double width, double height, this.animation,
{this.destroyOnFinish = false}) {
this.width = width;
this.height = height;
}
AnimationComponent.empty();
AnimationComponent.sequenced(
double width,
double height,
String imagePath,
int amount, {
int amountPerRow,
double textureX = 0.0,
double textureY = 0.0,
double textureWidth,
double textureHeight,
double stepTime,
bool loop = true,
this.destroyOnFinish = false,
}) {
this.width = width;
this.height = height;
animation = Animation.sequenced(
imagePath,
amount,
amountPerRow: amountPerRow,
textureX: textureX,
textureY: textureY,
textureWidth: textureWidth,
textureHeight: textureHeight,
stepTime: stepTime ?? 0.1,
loop: loop,
);
}
@override
bool loaded() => animation.loaded();
@override
bool destroy() => destroyOnFinish && animation.isLastFrame;
@override
void render(Canvas canvas) {
prepareCanvas(canvas);
animation.getSprite().render(canvas,
width: width, height: height, overridePaint: overridePaint);
}
@override
void update(double t) {
animation.update(t);
}
}