Skip to content

Commit 2332e76

Browse files
FlxAnimate 3.0.4 (before going full on 3.1.0)
1 parent 6bc8992 commit 2332e76

File tree

5 files changed

+418
-35
lines changed

5 files changed

+418
-35
lines changed

flxanimate/animate/FlxAnim.hx

+51
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package flxanimate.animate;
22

3+
34
import flixel.math.FlxMath;
45
import haxe.extern.EitherType;
56
import flxanimate.animate.SymbolParameters;
@@ -13,6 +14,7 @@ import flxanimate.data.AnimationData;
1314
import flixel.system.FlxSound;
1415
#end
1516

17+
1618
typedef SymbolStuff = {var instance:FlxElement; var frameRate:Float;};
1719
typedef ClickStuff = {
1820
?OnClick:Void->Void,
@@ -28,12 +30,16 @@ class FlxAnim implements IFlxDestroyable
2830
{
2931
public var length(get, never):Int;
3032

33+
3134
public var stageInstance:FlxElement;
3235

36+
3337
public var curInstance:FlxElement;
3438

39+
3540
public var metadata:FlxMetaData;
3641

42+
3743
public var curSymbol(get, null):FlxSymbol;
3844
public var finished(get, null):Bool;
3945
public var reversed(get, set):Bool;
@@ -49,28 +55,36 @@ class FlxAnim implements IFlxDestroyable
4955
public var isPlaying(default, null):Bool;
5056
public var onComplete:()->Void;
5157

58+
5259
public var framerate(default, set):Float;
5360

61+
5462
/**
5563
* Internal, used for each skip between frames.
5664
*/
5765
var frameDelay:Float;
5866

67+
5968
public var curFrame(get, set):Int;
6069

70+
6171
var animsMap:Map<String, SymbolStuff> = new Map();
6272

6373
/**
6474
* Internal, the parsed loop type
6575
*/
6676
var loopType(get, null):Loop;
6777

78+
6879
public var symbolType(get, set):SymbolT;
6980

81+
7082
var _parent:FlxAnimate;
7183

84+
7285
var _tick:Float;
7386

87+
7488
public function new(parent:FlxAnimate, ?coolParsed:AnimAtlas)
7589
{
7690
_tick = 0;
@@ -87,10 +101,13 @@ class FlxAnim implements IFlxDestroyable
87101

88102
setSymbols(animationFile);
89103

104+
90105
stageInstance = (animationFile.AN.STI != null) ? FlxElement.fromJSON(cast animationFile.AN.STI) : new FlxElement(new SymbolParameters(animationFile.AN.SN));
91106

107+
92108
curInstance = stageInstance;
93109

110+
94111
curFrame = stageInstance.symbol.firstFrame;
95112

96113
_parent.origin.copyFrom(stageInstance.symbol.transformationPoint);
@@ -111,6 +128,7 @@ class FlxAnim implements IFlxDestroyable
111128
var symbol = symbolDictionary.get(Name);
112129
if (symbol != null) curThing = {instance: (symbol.name == curSymbol.name) ? curInstance : new FlxElement(new SymbolParameters(Name)), frameRate: metadata.frameRate};
113130

131+
114132
if (curThing == null)
115133
{
116134
FlxG.log.error('there\'s no animation called "$Name"!');
@@ -124,6 +142,7 @@ class FlxAnim implements IFlxDestroyable
124142
if (curInstance != curThing.instance)
125143
curFrame = (Reverse) ? Frame - length : Frame;
126144

145+
127146
curInstance = curThing.instance;
128147
}
129148
if (Force || finished)
@@ -132,6 +151,7 @@ class FlxAnim implements IFlxDestroyable
132151
isPlaying = true;
133152
}
134153

154+
135155
public function pause()
136156
{
137157
isPlaying = false;
@@ -158,13 +178,21 @@ class FlxAnim implements IFlxDestroyable
158178
{
159179
if (frameDelay == 0 || !isPlaying || finished) return;
160180

181+
161182
_tick += elapsed;
162183

184+
163185
while (_tick > frameDelay)
164186
{
165187
(reversed) ? curFrame-- : curFrame++;
166188
_tick -= frameDelay;
189+
190+
191+
@:privateAccess
192+
curSymbol._shootCallback = true;
167193
}
194+
195+
168196

169197
if (finished)
170198
{
@@ -189,6 +217,7 @@ class FlxAnim implements IFlxDestroyable
189217
case PlayOnce: cast FlxMath.bound(Value, 0, curSymbol.length - 1);
190218
case _: Value;
191219
}
220+
192221
return curSymbol.curFrame;
193222
}
194223
/**
@@ -248,6 +277,7 @@ class FlxAnim implements IFlxDestroyable
248277
var i = Indices[index];
249278
var keyframe = new FlxKeyFrame(index);
250279

280+
251281
var params = new SymbolParameters(SymbolName, params.symbol.loop);
252282
params.firstFrame = i;
253283
keyframe.add(new FlxElement(params));
@@ -258,9 +288,11 @@ class FlxAnim implements IFlxDestroyable
258288

259289
symbolDictionary.set(Name, symbol);
260290

291+
261292
animsMap.set(Name, {instance: params, frameRate: FrameRate});
262293
}
263294

295+
264296
function set_framerate(value:Float):Float
265297
{
266298
frameDelay = 1 / value;
@@ -282,11 +314,13 @@ class FlxAnim implements IFlxDestroyable
282314
animsMap.set(Name, {instance: params, frameRate: FrameRate});
283315
}
284316

317+
285318
public function get_length()
286319
{
287320
return curSymbol.length;
288321
}
289322

323+
290324
public function getFrameLabel(name:String, ?layer:EitherType<Int, String>)
291325
{
292326
return curSymbol.getFrameLabel(name, layer);
@@ -306,11 +340,14 @@ class FlxAnim implements IFlxDestroyable
306340
{
307341
pause();
308342

343+
309344
var label = getFrameLabel(name);
310345

346+
311347
if (label != null)
312348
curFrame = label.index;
313349

350+
314351
play();
315352
}
316353
/**
@@ -333,16 +370,25 @@ class FlxAnim implements IFlxDestroyable
333370
return curSymbol.addCallbackTo(label, callback);
334371
}
335372

373+
336374
public function removeCallbackFrom(label:String, callback:()->Void)
337375
{
338376
return curSymbol.removeCallbackFrom(label, callback);
339377
}
340378

379+
341380
public function removeAllCallbacksFrom(label:String)
342381
{
343382
return curSymbol.removeAllCallbacksFrom(label);
344383
}
345384

385+
386+
public function getFrameLabels(?layer:EitherType<Int, String>)
387+
{
388+
return curSymbol.getFrameLabels(layer);
389+
}
390+
391+
346392
function get_loopType()
347393
{
348394
return curInstance.symbol.loop;
@@ -368,10 +414,12 @@ class FlxAnim implements IFlxDestroyable
368414
return animsMap.get(name);
369415
}
370416

417+
371418
public function getByInstance(instance:String, ?frame:Int = null, ?layer:EitherType<String, Int>)
372419
{
373420
if (frame == null) frame = curFrame;
374421

422+
375423
var symbol:FlxSymbol = null;
376424

377425
var layers = (layer == null) ? curSymbol.timeline.getList() : [curSymbol.timeline.get(layer)];
@@ -380,6 +428,7 @@ class FlxAnim implements IFlxDestroyable
380428
{
381429
if (layer == null) continue;
382430

431+
383432
for (element in layer.get(frame).getList())
384433
{
385434
if (element.symbol == null) continue;
@@ -395,11 +444,13 @@ class FlxAnim implements IFlxDestroyable
395444
return symbol;
396445
}
397446

447+
398448
function get_curSymbol()
399449
{
400450
return symbolDictionary.get(curInstance.symbol.name);
401451
}
402452

453+
403454
public function destroy()
404455
{
405456
isPlaying = false;

flxanimate/animate/FlxLayer.hx

+33-24
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,44 @@
1-
// Thought things could change, but the only thing changing is my self-esteem.
2-
// Why am I still alive? am I even being useful?
3-
// Who cares? I am just me, smiling and laughing with people as long as they don't notice my dissappearing, who would care?
4-
// I am judged, with a bat swinging around my head. Fortunately, I have brain damage because of it.
5-
// Who cares? I am just vibing, just "sad" one day and then happy again.
6-
// Who cares? I just gonna go through the window and fly away.
7-
// Why am I even holding myself from it? am I in love?
8-
// She doesn't even care about me, does she?
9-
// I don't wanna even know, since dead people don't have to think anymore, am I right?
10-
// Who cares? Just a few stabs, a rope or falling could end my suffering.
11-
// All those looks, all those insults, my mere presence would benefit if it disappeared.
12-
// But I am stupid to still be alive, working for a project that nobody cares.
13-
// But I am stupid to think I would be relevant to anyone, Even though they tell me I am not.
14-
// But I somehow try to believe as hard as I can to her, am I in love?
15-
// Everywhere is grey, what happened to me?
16-
// Am I broken? Can I reverse it?
17-
// Or am I just unfixable?
18-
// Who cares? I am just a stranger, with bad behaviour to many people and someone to be mocked at.
19-
// I wish to go back where I could be careless, back when I almost died.
20-
// Maybe I should've died there.
21-
221
package flxanimate.animate;
232

3+
4+
import flxanimate.data.AnimationData.LayerType;
245
import flixel.math.FlxMath;
256
import haxe.extern.EitherType;
267
import flxanimate.data.AnimationData.Frame;
278
import flixel.util.FlxDestroyUtil.IFlxDestroyable;
289
import flxanimate.data.AnimationData.Layers;
2910

11+
3012
class FlxLayer implements IFlxDestroyable
3113
{
3214
@:allow(flxanimate.animate.FlxTimeline)
3315
var _parent(default, set):FlxTimeline;
3416

3517
public var name(default, null):String;
3618

37-
19+
@:allow(flxanimate.animate.FlxKeyFrame)
20+
var _labels:Map<String, FlxKeyFrame>;
21+
22+
public var type:LayerType;
3823
var _keyframes(default, null):Array<FlxKeyFrame>;
3924

25+
4026
public var visible:Bool;
4127

28+
4229
public var length(get, null):Int;
4330

31+
4432
public function new(?name:String, ?keyframes:Array<FlxKeyFrame>)
4533
{
4634
this.name = name;
35+
type = Normal;
4736
_keyframes = (keyframes != null) ? keyframes : [];
4837
visible = true;
38+
_labels = [];
4939
}
5040

41+
5142
public function hide()
5243
{
5344
visible = false;
@@ -62,15 +53,22 @@ class FlxLayer implements IFlxDestroyable
6253
public function get(frame:EitherType<String, Int>)
6354
{
6455
var index = 0;
65-
if ((frame is Int))
56+
if ((frame is String))
57+
{
58+
if (!_labels.exists(frame)) return null;
59+
60+
return _labels.get(frame);
61+
}
62+
else
6663
{
6764
index = frame;
6865
if (index > length) return null;
6966
}
7067

68+
7169
for (keyframe in _keyframes)
7270
{
73-
if (keyframe.index + keyframe.duration > index || (frame is String) && keyframe.name == frame)
71+
if (keyframe.index + keyframe.duration > index)
7472
return keyframe;
7573
}
7674
return null;
@@ -80,6 +78,9 @@ class FlxLayer implements IFlxDestroyable
8078
{
8179
if (keyFrame == null) return null;
8280
var index = keyFrame.index;
81+
if (keyFrame.name != null)
82+
_labels.set(keyFrame.name, keyFrame);
83+
8384

8485
var keyframe = get(cast FlxMath.bound(index, 0, length - 1));
8586
if (length == 0)
@@ -89,10 +90,12 @@ class FlxLayer implements IFlxDestroyable
8990
}
9091
var difference:Int = cast Math.abs(index - keyframe.index);
9192

93+
9294
if (index == keyframe.index)
9395
{
9496
keyFrame.duration += keyframe.duration - 1;
9597

98+
9699
_keyframes.insert(_keyframes.indexOf(keyframe), keyFrame);
97100
_keyframes.remove(keyframe);
98101
keyframe.destroy();
@@ -105,6 +108,7 @@ class FlxLayer implements IFlxDestroyable
105108
_keyframes.insert(_keyframes.indexOf(keyframe) + 1, keyFrame);
106109
}
107110

111+
108112
keyFrame._parent = this;
109113
return keyFrame;
110114
}
@@ -153,6 +157,10 @@ class FlxLayer implements IFlxDestroyable
153157
if (layer == null) return null;
154158
var frames = [];
155159
var l = new FlxLayer(layer.LN);
160+
if (layer.LT != null || layer.Clpb != null)
161+
{
162+
l.type = (layer.LT != null) ? Clipper : Clipped(layer.Clpb);
163+
}
156164
if (layer.FR != null)
157165
{
158166
for (frame in layer.FR)
@@ -161,6 +169,7 @@ class FlxLayer implements IFlxDestroyable
161169
}
162170
}
163171

172+
164173
return l;
165174
}
166175
}

0 commit comments

Comments
 (0)