[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);
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();

View File

@ -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();

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
* 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) {