@@ -99,7 +99,7 @@ public void enableEvents(boolean v) {
99
99
private AnimationStateListener animationListener = new AnimationStateAdapter () {
100
100
@ Override
101
101
public void complete (TrackEntry entry ) {
102
- if (complete || entry .getTrackIndex () != 0 )
102
+ if (complete || ( entry != null && entry .getTrackIndex () != 0 ) )
103
103
return ;
104
104
105
105
loopCount ++;
@@ -181,13 +181,14 @@ public String[] getInternalAnimations(AnimationDesc anim) {
181
181
@ Override
182
182
public void update (float delta ) {
183
183
if (complete ) {
184
-
184
+
185
185
// keep updating secondary animation
186
186
// WARNING: It doesn't work with REVERSE ANIMATION
187
- if (secondaryAnimation != null && currentSource != null &&
188
- !((SkeletonCacheEntry ) currentSource ).animation .getTracks ().get (1 ).isComplete ())
187
+ if (secondaryAnimation != null && currentSource != null
188
+ && (!((SkeletonCacheEntry ) currentSource ).animation .getTracks ().get (1 ).isComplete ()
189
+ || ((SkeletonCacheEntry ) currentSource ).animation .getTracks ().get (1 ).getLoop ()))
189
190
updateAnimation (delta );
190
-
191
+
191
192
return ;
192
193
}
193
194
@@ -364,21 +365,25 @@ public void startAnimation(String id, Tween.Type repeatType, int count, ActionCa
364
365
public void setSecondaryAnimation (String animation ) {
365
366
secondaryAnimation = animation ;
366
367
SkeletonCacheEntry cs = (SkeletonCacheEntry ) currentSource ;
367
-
368
- if (animation == null ) {
369
- cs .animation .setEmptyAnimation (1 , 0.01f );
370
- return ;
371
- }
372
368
373
369
try {
374
- SpineAnimationDesc fa = (SpineAnimationDesc ) fanims .get (animation );
375
-
376
- if (fa == null ) {
377
- EngineLogger .error ("SpineRenderer:setCurrentFA Animation not found: " + animation );
378
- return ;
370
+
371
+ if (animation == null ) {
372
+ cs .animation .setEmptyAnimation (1 , 0 );
373
+ // cs.animation.clearTrack(1);
374
+ } else {
375
+
376
+ SpineAnimationDesc fa = (SpineAnimationDesc ) fanims .get (animation );
377
+
378
+ if (fa == null ) {
379
+ EngineLogger .error ("SpineRenderer:setCurrentFA Animation not found: " + animation );
380
+ return ;
381
+ }
382
+
383
+ cs .animation .setAnimation (1 , secondaryAnimation , fa .animationType == Tween .Type .REPEAT );
379
384
}
380
-
381
- cs . animation . setAnimation ( 1 , secondaryAnimation , fa . animationType == Tween . Type . REPEAT );
385
+
386
+ updateAnimation ( 0 );
382
387
} catch (Exception e ) {
383
388
EngineLogger .error ("SpineRenderer:setCurrentFA " + e .getMessage ());
384
389
}
@@ -390,11 +395,12 @@ private void setCurrentAnimation() {
390
395
cs .skeleton .setToSetupPose ();
391
396
cs .skeleton .setFlipX (flipX );
392
397
cs .animation .setTimeScale (currentAnimation .duration );
398
+ cs .animation .clearTracks ();
393
399
cs .animation .setAnimation (0 , currentAnimation .id , currentAnimationType == Tween .Type .REPEAT );
394
-
395
- if (secondaryAnimation != null )
400
+
401
+ if (secondaryAnimation != null )
396
402
setSecondaryAnimation (secondaryAnimation );
397
-
403
+
398
404
updateAnimation (lastAnimationTime );
399
405
computeBbox ();
400
406
@@ -664,9 +670,13 @@ public void retrieveAssets() {
664
670
@ Override
665
671
public void dispose () {
666
672
for (Entry <String , CacheEntry > entry : sourceCache .entrySet ()) {
667
- if (entry .getValue ().refCounter > 0 )
668
- EngineAssetManager .getInstance ()
669
- .unload (EngineAssetManager .SPINE_DIR + entry .getKey () + EngineAssetManager .SPINE_EXT );
673
+
674
+ if (entry .getValue ().refCounter > 0 ) {
675
+ String filename = EngineAssetManager .SPINE_DIR + entry .getKey () + EngineAssetManager .SPINE_EXT ;
676
+
677
+ if (EngineAssetManager .getInstance ().isLoaded (filename ))
678
+ EngineAssetManager .getInstance ().unload (filename );
679
+ }
670
680
}
671
681
672
682
sourceCache .clear ();
@@ -716,8 +726,8 @@ public void read(Json json, JsonValue jsonData) {
716
726
lastAnimationTime = json .readValue ("lastAnimationTime" , Float .class , jsonData );
717
727
complete = json .readValue ("complete" , Boolean .class , jsonData );
718
728
loopCount = json .readValue ("loopCount" , int .class , loopCount , jsonData );
719
-
720
- secondaryAnimation = json .readValue ("secondaryAnimation" , String .class , (String )null , jsonData );
729
+
730
+ secondaryAnimation = json .readValue ("secondaryAnimation" , String .class , (String ) null , jsonData );
721
731
}
722
732
}
723
733
}
0 commit comments