@@ -11,11 +11,11 @@ import '../core/constant.dart';
11
11
///
12
12
////////////////////////////////////////////////////////////
13
13
class Animator {
14
- Function onComplete;
14
+ Function ? onComplete;
15
15
String status = "stop" ;
16
16
17
17
ListMap _aniList = new ListMap ();
18
- Animation _currentAni;
18
+ Animation ? _currentAni;
19
19
int _framesLength = - 1 ;
20
20
21
21
bool get isEnabled {
@@ -32,27 +32,28 @@ class Animator {
32
32
}
33
33
34
34
dynamic getCurrentFrameKey () {
35
- return _currentAni != null ? _currentAni.getCurrentFrameKey () : 0 ;
35
+ return _currentAni != null ? _currentAni? .getCurrentFrameKey () : 0 ;
36
36
}
37
37
38
38
////////////////////////////////////////////////////////////
39
39
///
40
40
/// Play and Stop
41
41
///
42
42
////////////////////////////////////////////////////////////
43
- void play (String name, [int rate, bool loop = false ]) {
44
- Animation ani = _aniList.getItem (name);
45
- if (ani == null )
43
+ void play (String name, [int ? rate, bool loop = false ]) {
44
+ Animation ? ani = _aniList.getItem (name);
45
+ if (ani == null ) {
46
46
throw ("Zerker:: Sorry, there is no corresponding animation information." );
47
-
48
- ani.rate = rate ?? ani.rate;
49
- ani.loop = loop ?? ani.loop;
50
- _currentAni = ani;
51
- _currentAni.reset ();
52
- this .status = "play" ;
47
+ } else {
48
+ ani.rate = rate ?? ani.rate;
49
+ ani.loop = loop;
50
+ _currentAni = ani;
51
+ _currentAni? .reset ();
52
+ this .status = "play" ;
53
+ }
53
54
}
54
55
55
- void stop ([String name]) {
56
+ void stop ([String ? name]) {
56
57
if (name != null ) {
57
58
this .play (name, 9999 );
58
59
}
@@ -66,7 +67,7 @@ class Animator {
66
67
///
67
68
////////////////////////////////////////////////////////////
68
69
void make (String name,
69
- [List frames, int rate = Constant .RATE , bool loop = false ]) {
70
+ [List ? frames, int rate = Constant .RATE , bool loop = false ]) {
70
71
Animation ani = new Animation (name, frames, rate, loop);
71
72
ani.framesLength = framesLength;
72
73
ani.onComplete = onComplete;
@@ -75,12 +76,15 @@ class Animator {
75
76
}
76
77
77
78
void add (
78
- {String name, List frames, int rate = Constant .RATE , bool loop = false }) {
79
+ {String name = "" ,
80
+ List ? frames,
81
+ int rate = Constant .RATE ,
82
+ bool loop = false }) {
79
83
return make (name, frames, rate, loop);
80
84
}
81
85
82
86
void remove (String name, [bool destroy = false ]) {
83
- Animation ani = _aniList.getItem (name);
87
+ Animation ? ani = _aniList.getItem (name);
84
88
if (ani != null && destroy) {
85
89
ani.dispose ();
86
90
}
@@ -96,7 +100,7 @@ class Animator {
96
100
void update (int time) {
97
101
if (this .status == "stop" ) return ;
98
102
99
- _currentAni.update (time);
103
+ _currentAni? .update (time);
100
104
}
101
105
102
106
////////////////////////////////////////////////////////////
@@ -110,7 +114,6 @@ class Animator {
110
114
111
115
dispose () {
112
116
this .clear ();
113
-
114
117
onComplete = null ;
115
118
}
116
119
}
0 commit comments