public float transitionTargetTime;
/** Whether an action is being performed. Do not alter this value. */
public boolean inAction;
+
+ private boolean justChangedAnimation = false;
/** Construct a new AnimationController.
* @param target The {@link ModelInstance} on which the animations will be performed. */
}
private AnimationDesc obtain(final Animation anim, int loopCount, float speed, final AnimationListener listener) {
+ if (anim == null)
+ return null;
final AnimationDesc result = animationPool.obtain();
result.animation = anim;
result.listener = listener;
}
private AnimationDesc obtain(final String id, int loopCount, float speed, final AnimationListener listener) {
+ if (id == null)
+ return null;
final Animation anim = target.getAnimation(id);
if (anim == null)
throw new GdxRuntimeException("Unknown animation: "+id);
/** Update any animations currently being played.
* @param delta The time elapsed since last update, change this to alter the overall speed (can be negative). */
public void update(float delta) {
+ if (previous != null && ((transitionCurrentTime += delta) >= transitionTargetTime)) {
+ removeAnimation(previous.animation);
+ justChangedAnimation = true;
+ animationPool.free(previous);
+ previous = null;
+ }
+ if (justChangedAnimation) {
+ target.calculateTransforms();
+ justChangedAnimation = false;
+ }
if (current == null || current.loopCount == 0 || current.animation == null)
return;
+ justChangedAnimation = false;
updating = true;
final float remain = current.update(delta);
if (remain != 0f && queued != null) {
update(remain);
return;
}
- if (previous != null && ((transitionCurrentTime += delta) >= transitionTargetTime)) {
- animationPool.free(previous);
- previous = null;
- }
if (previous != null)
applyAnimations(previous.animation, previous.time, current.animation, current.time, transitionCurrentTime / transitionTargetTime);
else
if (current == null)
current = anim;
else {
- if (current.animation == anim.animation)
+ if (anim != null && current.animation == anim.animation)
anim.time = current.time;
+ else
+ removeAnimation(current.animation);
animationPool.free(current);
current = anim;
}
+ justChangedAnimation = true;
return anim;
}
current = anim;
else if (inAction)
queue(anim, transitionTime);
- else if (current.animation == anim.animation) {
+ else if (anim != null && current.animation == anim.animation) {
anim.time = current.time;
animationPool.free(current);
current = anim;
package com.badlogic.gdx.graphics.g3d.utils;
+import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.model.Animation;
import com.badlogic.gdx.graphics.g3d.model.Node;
}
}
}
+
+ /** Remove the specified animation, by marking the affected nodes as not animated. When switching animation, this should
+ * be call prior to applyAnimation(s). */
+ protected void removeAnimation(final Animation animation) {
+ for (final NodeAnimation nodeAnim : animation.nodeAnimations) {
+ nodeAnim.node.isAnimated = false;
+ }
+ }
}