From 088a8704637d15656784d90c8282be2175a17ec1 Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Thu, 1 Jun 2017 21:14:34 +0200 Subject: [PATCH] [libgdx] Return true from AnimationState#apply if any animation was applied. Makes it easier to know when you don't need to call updateWorldTransform. --- .../src/com/esotericsoftware/spine/SimpleTest2.java | 4 ++-- .../src/com/esotericsoftware/spine/SimpleTest3.java | 4 ++-- .../src/com/esotericsoftware/spine/AnimationState.java | 9 ++++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest2.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest2.java index 8958c84f3..88c92e79c 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest2.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest2.java @@ -146,8 +146,8 @@ public class SimpleTest2 extends ApplicationAdapter { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - state.apply(skeleton); // Poses skeleton using current animations. This sets the bones' local SRT. - skeleton.updateWorldTransform(); // Uses the bones' local SRT to compute their world SRT. + if (state.apply(skeleton)) // Poses skeleton using current animations. This sets the bones' local SRT. + skeleton.updateWorldTransform(); // Uses the bones' local SRT to compute their world SRT. // Configure the camera, SpriteBatch, and SkeletonRendererDebug. camera.update(); diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest3.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest3.java index d206fc142..bc34141de 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest3.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest3.java @@ -82,8 +82,8 @@ public class SimpleTest3 extends ApplicationAdapter { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - state.apply(skeleton); // Poses skeleton using current animations. This sets the bones' local SRT. - skeleton.updateWorldTransform(); // Uses the bones' local SRT to compute their world SRT. + if (state.apply(skeleton)) // Poses skeleton using current animations. This sets the bones' local SRT. + skeleton.updateWorldTransform(); // Uses the bones' local SRT to compute their world SRT. // Configure the camera, SpriteBatch, and SkeletonRendererDebug. camera.update(); diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java index d55b4f438..991ef0274 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java @@ -158,16 +158,18 @@ public class AnimationState { } /** Poses the skeleton using the track entry animations. There are no side effects other than invoking listeners, so the - * animation state can be applied to multiple skeletons to pose them identically. */ - public void apply (Skeleton skeleton) { + * animation state can be applied to multiple skeletons to pose them identically. + * @return True if any animations were applied. */ + public boolean apply (Skeleton skeleton) { if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null."); if (animationsChanged) animationsChanged(); Array events = this.events; - + boolean applied = false; for (int i = 0, n = tracks.size; i < n; i++) { TrackEntry current = tracks.get(i); if (current == null || current.delay > 0) continue; + applied = true; // Apply mixing from entries first. float mix = current.alpha; @@ -206,6 +208,7 @@ public class AnimationState { } queue.drain(); + return applied; } private float applyMixingFrom (TrackEntry to, Skeleton skeleton) {