Skip to content

Commit 96d16f3

Browse files
committed
Some little fixes in Spine Secondary Animations
1 parent d512fc1 commit 96d16f3

File tree

2 files changed

+37
-26
lines changed

2 files changed

+37
-26
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
******************************************************************************/
16-
package com.bladecoder.engine.spine;
16+
package com.bladecoder.engine.actions;
1717

1818
import com.bladecoder.engine.actions.Action;
1919
import com.bladecoder.engine.actions.ActionDescription;
@@ -23,6 +23,7 @@
2323
import com.bladecoder.engine.model.SpriteActor;
2424
import com.bladecoder.engine.model.VerbRunner;
2525
import com.bladecoder.engine.model.World;
26+
import com.bladecoder.engine.spine.SpineRenderer;
2627
import com.bladecoder.engine.util.EngineLogger;
2728

2829
@ActionDescription("ONLY FOR SPINE ACTORS: Sets a secondary animation")

blade-engine-spine-plugin/src/main/java/com/bladecoder/engine/spine/SpineRenderer.java

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void enableEvents(boolean v) {
9999
private AnimationStateListener animationListener = new AnimationStateAdapter() {
100100
@Override
101101
public void complete(TrackEntry entry) {
102-
if (complete || entry.getTrackIndex() != 0)
102+
if (complete || (entry != null && entry.getTrackIndex() != 0))
103103
return;
104104

105105
loopCount++;
@@ -181,13 +181,14 @@ public String[] getInternalAnimations(AnimationDesc anim) {
181181
@Override
182182
public void update(float delta) {
183183
if (complete) {
184-
184+
185185
// keep updating secondary animation
186186
// 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()))
189190
updateAnimation(delta);
190-
191+
191192
return;
192193
}
193194

@@ -364,21 +365,25 @@ public void startAnimation(String id, Tween.Type repeatType, int count, ActionCa
364365
public void setSecondaryAnimation(String animation) {
365366
secondaryAnimation = animation;
366367
SkeletonCacheEntry cs = (SkeletonCacheEntry) currentSource;
367-
368-
if(animation == null) {
369-
cs.animation.setEmptyAnimation(1, 0.01f);
370-
return;
371-
}
372368

373369
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);
379384
}
380-
381-
cs.animation.setAnimation(1, secondaryAnimation, fa.animationType == Tween.Type.REPEAT);
385+
386+
updateAnimation(0);
382387
} catch (Exception e) {
383388
EngineLogger.error("SpineRenderer:setCurrentFA " + e.getMessage());
384389
}
@@ -390,11 +395,12 @@ private void setCurrentAnimation() {
390395
cs.skeleton.setToSetupPose();
391396
cs.skeleton.setFlipX(flipX);
392397
cs.animation.setTimeScale(currentAnimation.duration);
398+
cs.animation.clearTracks();
393399
cs.animation.setAnimation(0, currentAnimation.id, currentAnimationType == Tween.Type.REPEAT);
394-
395-
if(secondaryAnimation != null)
400+
401+
if (secondaryAnimation != null)
396402
setSecondaryAnimation(secondaryAnimation);
397-
403+
398404
updateAnimation(lastAnimationTime);
399405
computeBbox();
400406

@@ -664,9 +670,13 @@ public void retrieveAssets() {
664670
@Override
665671
public void dispose() {
666672
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+
}
670680
}
671681

672682
sourceCache.clear();
@@ -716,8 +726,8 @@ public void read(Json json, JsonValue jsonData) {
716726
lastAnimationTime = json.readValue("lastAnimationTime", Float.class, jsonData);
717727
complete = json.readValue("complete", Boolean.class, jsonData);
718728
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);
721731
}
722732
}
723733
}

0 commit comments

Comments
 (0)