瀏覽代碼

[libgdx] Return true from AnimationState#apply if any animation was applied.

Makes it easier to know when you don't need to call updateWorldTransform.
NathanSweet 8 年之前
父節點
當前提交
088a870463

+ 2 - 2
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();

+ 2 - 2
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();

+ 6 - 3
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<Event> 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) {