1
1
package flxanimate .animate ;
2
2
3
+
3
4
import flixel .math .FlxMath ;
4
5
import haxe .extern .EitherType ;
5
6
import flxanimate .animate .SymbolParameters ;
@@ -13,6 +14,7 @@ import flxanimate.data.AnimationData;
13
14
import flixel .system .FlxSound ;
14
15
#end
15
16
17
+
16
18
typedef SymbolStuff = {var instance : FlxElement ; var frameRate : Float ;};
17
19
typedef ClickStuff = {
18
20
? OnClick : Void -> Void ,
@@ -28,12 +30,16 @@ class FlxAnim implements IFlxDestroyable
28
30
{
29
31
public var length (get , never ): Int ;
30
32
33
+
31
34
public var stageInstance : FlxElement ;
32
35
36
+
33
37
public var curInstance : FlxElement ;
34
38
39
+
35
40
public var metadata : FlxMetaData ;
36
41
42
+
37
43
public var curSymbol (get , null ): FlxSymbol ;
38
44
public var finished (get , null ): Bool ;
39
45
public var reversed (get , set ): Bool ;
@@ -49,28 +55,36 @@ class FlxAnim implements IFlxDestroyable
49
55
public var isPlaying (default , null ): Bool ;
50
56
public var onComplete : ()-> Void ;
51
57
58
+
52
59
public var framerate (default , set ): Float ;
53
60
61
+
54
62
/**
55
63
* Internal, used for each skip between frames.
56
64
*/
57
65
var frameDelay : Float ;
58
66
67
+
59
68
public var curFrame (get , set ): Int ;
60
69
70
+
61
71
var animsMap : Map <String , SymbolStuff > = new Map ();
62
72
63
73
/**
64
74
* Internal, the parsed loop type
65
75
*/
66
76
var loopType (get , null ): Loop ;
67
77
78
+
68
79
public var symbolType (get , set ): SymbolT ;
69
80
81
+
70
82
var _parent : FlxAnimate ;
71
83
84
+
72
85
var _tick : Float ;
73
86
87
+
74
88
public function new (parent : FlxAnimate , ? coolParsed : AnimAtlas )
75
89
{
76
90
_tick = 0 ;
@@ -87,10 +101,13 @@ class FlxAnim implements IFlxDestroyable
87
101
88
102
setSymbols (animationFile );
89
103
104
+
90
105
stageInstance = (animationFile. AN .STI != null ) ? FlxElement .fromJSON (cast animationFile. AN .STI ) : new FlxElement (new SymbolParameters (animationFile. AN .SN ));
91
106
107
+
92
108
curInstance = stageInstance ;
93
109
110
+
94
111
curFrame = stageInstance .symbol .firstFrame ;
95
112
96
113
_parent .origin .copyFrom (stageInstance .symbol .transformationPoint );
@@ -111,6 +128,7 @@ class FlxAnim implements IFlxDestroyable
111
128
var symbol = symbolDictionary .get (Name );
112
129
if (symbol != null ) curThing = {instance : (symbol .name == curSymbol .name ) ? curInstance : new FlxElement (new SymbolParameters (Name )), frameRate : metadata .frameRate };
113
130
131
+
114
132
if (curThing == null )
115
133
{
116
134
FlxG .log .error (' there\' s no animation called " $Name "!' );
@@ -124,6 +142,7 @@ class FlxAnim implements IFlxDestroyable
124
142
if (curInstance != curThing .instance )
125
143
curFrame = (Reverse ) ? Frame - length : Frame ;
126
144
145
+
127
146
curInstance = curThing .instance ;
128
147
}
129
148
if (Force || finished )
@@ -132,6 +151,7 @@ class FlxAnim implements IFlxDestroyable
132
151
isPlaying = true ;
133
152
}
134
153
154
+
135
155
public function pause ()
136
156
{
137
157
isPlaying = false ;
@@ -158,13 +178,21 @@ class FlxAnim implements IFlxDestroyable
158
178
{
159
179
if (frameDelay == 0 || ! isPlaying || finished ) return ;
160
180
181
+
161
182
_tick + = elapsed ;
162
183
184
+
163
185
while (_tick > frameDelay )
164
186
{
165
187
(reversed ) ? curFrame -- : curFrame ++ ;
166
188
_tick - = frameDelay ;
189
+
190
+
191
+ @:privateAccess
192
+ curSymbol ._shootCallback = true ;
167
193
}
194
+
195
+
168
196
169
197
if (finished )
170
198
{
@@ -189,6 +217,7 @@ class FlxAnim implements IFlxDestroyable
189
217
case PlayOnce : cast FlxMath .bound (Value , 0 , curSymbol .length - 1 );
190
218
case _ : Value ;
191
219
}
220
+
192
221
return curSymbol .curFrame ;
193
222
}
194
223
/**
@@ -248,6 +277,7 @@ class FlxAnim implements IFlxDestroyable
248
277
var i = Indices [index ];
249
278
var keyframe = new FlxKeyFrame (index );
250
279
280
+
251
281
var params = new SymbolParameters (SymbolName , params .symbol .loop );
252
282
params .firstFrame = i ;
253
283
keyframe .add (new FlxElement (params ));
@@ -258,9 +288,11 @@ class FlxAnim implements IFlxDestroyable
258
288
259
289
symbolDictionary .set (Name , symbol );
260
290
291
+
261
292
animsMap .set (Name , {instance : params , frameRate : FrameRate });
262
293
}
263
294
295
+
264
296
function set_framerate (value : Float ): Float
265
297
{
266
298
frameDelay = 1 / value ;
@@ -282,11 +314,13 @@ class FlxAnim implements IFlxDestroyable
282
314
animsMap .set (Name , {instance : params , frameRate : FrameRate });
283
315
}
284
316
317
+
285
318
public function get_length ()
286
319
{
287
320
return curSymbol .length ;
288
321
}
289
322
323
+
290
324
public function getFrameLabel (name : String , ? layer : EitherType <Int , String >)
291
325
{
292
326
return curSymbol .getFrameLabel (name , layer );
@@ -306,11 +340,14 @@ class FlxAnim implements IFlxDestroyable
306
340
{
307
341
pause ();
308
342
343
+
309
344
var label = getFrameLabel (name );
310
345
346
+
311
347
if (label != null )
312
348
curFrame = label .index ;
313
349
350
+
314
351
play ();
315
352
}
316
353
/**
@@ -333,16 +370,25 @@ class FlxAnim implements IFlxDestroyable
333
370
return curSymbol .addCallbackTo (label , callback );
334
371
}
335
372
373
+
336
374
public function removeCallbackFrom (label : String , callback : ()-> Void )
337
375
{
338
376
return curSymbol .removeCallbackFrom (label , callback );
339
377
}
340
378
379
+
341
380
public function removeAllCallbacksFrom (label : String )
342
381
{
343
382
return curSymbol .removeAllCallbacksFrom (label );
344
383
}
345
384
385
+
386
+ public function getFrameLabels (? layer : EitherType <Int , String >)
387
+ {
388
+ return curSymbol .getFrameLabels (layer );
389
+ }
390
+
391
+
346
392
function get_loopType ()
347
393
{
348
394
return curInstance .symbol .loop ;
@@ -368,10 +414,12 @@ class FlxAnim implements IFlxDestroyable
368
414
return animsMap .get (name );
369
415
}
370
416
417
+
371
418
public function getByInstance (instance : String , ? frame : Int = null , ? layer : EitherType <String , Int >)
372
419
{
373
420
if (frame == null ) frame = curFrame ;
374
421
422
+
375
423
var symbol : FlxSymbol = null ;
376
424
377
425
var layers = (layer == null ) ? curSymbol .timeline .getList () : [curSymbol .timeline .get (layer )];
@@ -380,6 +428,7 @@ class FlxAnim implements IFlxDestroyable
380
428
{
381
429
if (layer == null ) continue ;
382
430
431
+
383
432
for (element in layer .get (frame ).getList ())
384
433
{
385
434
if (element .symbol == null ) continue ;
@@ -395,11 +444,13 @@ class FlxAnim implements IFlxDestroyable
395
444
return symbol ;
396
445
}
397
446
447
+
398
448
function get_curSymbol ()
399
449
{
400
450
return symbolDictionary .get (curInstance .symbol .name );
401
451
}
402
452
453
+
403
454
public function destroy ()
404
455
{
405
456
isPlaying = false ;
0 commit comments