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

Makes it easier to know when you don't need to call updateWorldTransform.
This commit is contained in:
NathanSweet 2017-06-01 21:14:34 +02:00
parent 787170fa46
commit 088a870463
3 changed files with 10 additions and 7 deletions

View File

@ -146,8 +146,8 @@ public class SimpleTest2 extends ApplicationAdapter {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
state.apply(skeleton); // Poses skeleton using current animations. This sets the bones' local 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. skeleton.updateWorldTransform(); // Uses the bones' local SRT to compute their world SRT.
// Configure the camera, SpriteBatch, and SkeletonRendererDebug. // Configure the camera, SpriteBatch, and SkeletonRendererDebug.
camera.update(); camera.update();

View File

@ -82,8 +82,8 @@ public class SimpleTest3 extends ApplicationAdapter {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
state.apply(skeleton); // Poses skeleton using current animations. This sets the bones' local 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. skeleton.updateWorldTransform(); // Uses the bones' local SRT to compute their world SRT.
// Configure the camera, SpriteBatch, and SkeletonRendererDebug. // Configure the camera, SpriteBatch, and SkeletonRendererDebug.
camera.update(); camera.update();

View File

@ -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 /** 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. */ * animation state can be applied to multiple skeletons to pose them identically.
public void apply (Skeleton skeleton) { * @return True if any animations were applied. */
public boolean apply (Skeleton skeleton) {
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null."); if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
if (animationsChanged) animationsChanged(); if (animationsChanged) animationsChanged();
Array<Event> events = this.events; Array<Event> events = this.events;
boolean applied = false;
for (int i = 0, n = tracks.size; i < n; i++) { for (int i = 0, n = tracks.size; i < n; i++) {
TrackEntry current = tracks.get(i); TrackEntry current = tracks.get(i);
if (current == null || current.delay > 0) continue; if (current == null || current.delay > 0) continue;
applied = true;
// Apply mixing from entries first. // Apply mixing from entries first.
float mix = current.alpha; float mix = current.alpha;
@ -206,6 +208,7 @@ public class AnimationState {
} }
queue.drain(); queue.drain();
return applied;
} }
private float applyMixingFrom (TrackEntry to, Skeleton skeleton) { private float applyMixingFrom (TrackEntry to, Skeleton skeleton) {