/** Changes the current animation by blending the new on top of the old during the transition time. * @param id The ID of the {@link Animation} within the {@link ModelInstance}. * @param loopCount The number of times to loop the animation, zero to play the animation only once, negative to continuously * loop the animation. * @param listener The {@link AnimationListener} which will be informed when the animation is looped or completed. * @param transitionTime The time to transition the new animation on top of the currently playing animation (if any). * @return The {@link AnimationDesc} which can be read to get the progress of the animation. Will be invalid when the animation * is completed. */ public AnimationDesc animate (final String id, int loopCount, final AnimationListener listener, float transitionTime) { return animate(id, loopCount, 1.0f, listener, transitionTime); }
/** Changes the current animation by blending the new on top of the old during the transition time. * @param id The ID of the {@link Animation} within the {@link ModelInstance}. * @param listener The {@link AnimationListener} which will be informed when the animation is looped or completed. * @param transitionTime The time to transition the new animation on top of the currently playing animation (if any). * @return The {@link AnimationDesc} which can be read to get the progress of the animation. Will be invalid when the animation * is completed. */ public AnimationDesc animate (final String id, final AnimationListener listener, float transitionTime) { return animate(id, 1, 1.0f, listener, transitionTime); }
/** Changes the current animation by blending the new on top of the old during the transition time. * @param id The ID of the {@link Animation} within the {@link ModelInstance}. * @param loopCount The number of times to loop the animation, zero to play the animation only once, negative to continuously * loop the animation. * @param listener The {@link AnimationListener} which will be informed when the animation is looped or completed. * @param transitionTime The time to transition the new animation on top of the currently playing animation (if any). * @return The {@link AnimationDesc} which can be read to get the progress of the animation. Will be invalid when the animation * is completed. */ public AnimationDesc animate (final String id, int loopCount, final AnimationListener listener, float transitionTime) { return animate(id, loopCount, 1.0f, listener, transitionTime); }
/** Changes the current animation by blending the new on top of the old during the transition time. * @param id The ID of the {@link Animation} within the {@link ModelInstance}. * @param transitionTime The time to transition the new animation on top of the currently playing animation (if any). * @return The {@link AnimationDesc} which can be read to get the progress of the animation. Will be invalid when the animation * is completed. */ public AnimationDesc animate (final String id, float transitionTime) { return animate(id, 1, 1.0f, null, transitionTime); }
/** Changes the current animation by blending the new on top of the old during the transition time. * @param id The ID of the {@link Animation} within the {@link ModelInstance}. * @param transitionTime The time to transition the new animation on top of the currently playing animation (if any). * @return The {@link AnimationDesc} which can be read to get the progress of the animation. Will be invalid when the animation * is completed. */ public AnimationDesc animate (final String id, float transitionTime) { return animate(id, 1, 1.0f, null, transitionTime); }
/** Changes the current animation by blending the new on top of the old during the transition time. * @param id The ID of the {@link Animation} within the {@link ModelInstance}. * @param listener The {@link AnimationListener} which will be informed when the animation is looped or completed. * @param transitionTime The time to transition the new animation on top of the currently playing animation (if any). * @return The {@link AnimationDesc} which can be read to get the progress of the animation. Will be invalid when the animation * is completed. */ public AnimationDesc animate (final String id, final AnimationListener listener, float transitionTime) { return animate(id, 1, 1.0f, listener, transitionTime); }
/** Changes the current animation by blending the new on top of the old during the transition time. * @param id The ID of the {@link Animation} within the {@link ModelInstance}. * @param loopCount The number of times to loop the animation, zero to play the animation only once, negative to continuously * loop the animation. * @param speed The speed at which the animation should be played. Default is 1.0f. A value of 2.0f will play the animation at * twice the normal speed, a value of 0.5f will play the animation at half the normal speed, etc. This value can be * negative, causing the animation to played in reverse. This value cannot be zero. * @param listener The {@link AnimationListener} which will be informed when the animation is looped or completed. * @param transitionTime The time to transition the new animation on top of the currently playing animation (if any). * @return The {@link AnimationDesc} which can be read to get the progress of the animation. Will be invalid when the animation * is completed. */ public AnimationDesc animate (final String id, int loopCount, float speed, final AnimationListener listener, float transitionTime) { return animate(id, 0f, -1f, loopCount, speed, listener, transitionTime); }
/** Changes the current animation by blending the new on top of the old during the transition time. * @param id The ID of the {@link Animation} within the {@link ModelInstance}. * @param loopCount The number of times to loop the animation, zero to play the animation only once, negative to continuously * loop the animation. * @param speed The speed at which the animation should be played. Default is 1.0f. A value of 2.0f will play the animation at * twice the normal speed, a value of 0.5f will play the animation at half the normal speed, etc. This value can be * negative, causing the animation to played in reverse. This value cannot be zero. * @param listener The {@link AnimationListener} which will be informed when the animation is looped or completed. * @param transitionTime The time to transition the new animation on top of the currently playing animation (if any). * @return The {@link AnimationDesc} which can be read to get the progress of the animation. Will be invalid when the animation * is completed. */ public AnimationDesc animate (final String id, int loopCount, float speed, final AnimationListener listener, float transitionTime) { return animate(id, 0f, -1f, loopCount, speed, listener, transitionTime); }
/** Changes the current animation by blending the new on top of the old during the transition time. */ protected AnimationDesc animate (final Animation anim, float offset, float duration, int loopCount, float speed, final AnimationListener listener, float transitionTime) { return animate(obtain(anim, offset, duration, loopCount, speed, listener), transitionTime); }
/** Queue an animation to be applied when the current is finished. If current is continuous it will be synced on next loop. */ protected AnimationDesc queue (final AnimationDesc anim, float transitionTime) { if (current == null || current.loopCount == 0) animate(anim, transitionTime); else { if (queued != null) animationPool.free(queued); queued = anim; queuedTransitionTime = transitionTime; if (current.loopCount < 0) current.loopCount = 1; } return anim; }
/** Queue an animation to be applied when the current is finished. If current is continuous it will be synced on next loop. */ protected AnimationDesc queue (final AnimationDesc anim, float transitionTime) { if (current == null || current.loopCount == 0) animate(anim, transitionTime); else { if (queued != null) animationPool.free(queued); queued = anim; queuedTransitionTime = transitionTime; if (current.loopCount < 0) current.loopCount = 1; } return anim; }
/** Changes the current animation by blending the new on top of the old during the transition time. */ protected AnimationDesc animate (final Animation anim, float offset, float duration, int loopCount, float speed, final AnimationListener listener, float transitionTime) { return animate(obtain(anim, offset, duration, loopCount, speed, listener), transitionTime); }
/** Changes the current animation by blending the new on top of the old during the transition time. * @param id The ID of the {@link Animation} within the {@link ModelInstance}. * @param offset The offset in seconds to the start of the animation. * @param duration The duration in seconds of the animation (or negative to play till the end of the animation). * @param loopCount The number of times to loop the animation, zero to play the animation only once, negative to continuously * loop the animation. * @param speed The speed at which the animation should be played. Default is 1.0f. A value of 2.0f will play the animation at * twice the normal speed, a value of 0.5f will play the animation at half the normal speed, etc. This value can be * negative, causing the animation to played in reverse. This value cannot be zero. * @param listener The {@link AnimationListener} which will be informed when the animation is looped or completed. * @param transitionTime The time to transition the new animation on top of the currently playing animation (if any). * @return The {@link AnimationDesc} which can be read to get the progress of the animation. Will be invalid when the animation * is completed. */ public AnimationDesc animate (final String id, float offset, float duration, int loopCount, float speed, final AnimationListener listener, float transitionTime) { return animate(obtain(id, offset, duration, loopCount, speed, listener), transitionTime); }
/** Changes the current animation by blending the new on top of the old during the transition time. * @param id The ID of the {@link Animation} within the {@link ModelInstance}. * @param offset The offset in seconds to the start of the animation. * @param duration The duration in seconds of the animation (or negative to play till the end of the animation). * @param loopCount The number of times to loop the animation, zero to play the animation only once, negative to continuously * loop the animation. * @param speed The speed at which the animation should be played. Default is 1.0f. A value of 2.0f will play the animation at * twice the normal speed, a value of 0.5f will play the animation at half the normal speed, etc. This value can be * negative, causing the animation to played in reverse. This value cannot be zero. * @param listener The {@link AnimationListener} which will be informed when the animation is looped or completed. * @param transitionTime The time to transition the new animation on top of the currently playing animation (if any). * @return The {@link AnimationDesc} which can be read to get the progress of the animation. Will be invalid when the animation * is completed. */ public AnimationDesc animate (final String id, float offset, float duration, int loopCount, float speed, final AnimationListener listener, float transitionTime) { return animate(obtain(id, offset, duration, loopCount, speed, listener), transitionTime); }
/** Apply an action animation on top of the current animation. */ protected AnimationDesc action (final AnimationDesc anim, float transitionTime) { if (anim.loopCount < 0) throw new GdxRuntimeException("An action cannot be continuous"); if (current == null || current.loopCount == 0) animate(anim, transitionTime); else { AnimationDesc toQueue = inAction ? null : obtain(current); inAction = false; animate(anim, transitionTime); inAction = true; if (toQueue != null) queue(toQueue, transitionTime); } return anim; } }
/** Apply an action animation on top of the current animation. */ protected AnimationDesc action (final AnimationDesc anim, float transitionTime) { if (anim.loopCount < 0) throw new GdxRuntimeException("An action cannot be continuous"); if (current == null || current.loopCount == 0) animate(anim, transitionTime); else { AnimationDesc toQueue = inAction ? null : obtain(current); inAction = false; animate(anim, transitionTime); inAction = true; if (toQueue != null) queue(toQueue, transitionTime); } return anim; } }
protected void switchAnimation () { for (ObjectMap.Entry<ModelInstance, AnimationController> e : animationControllers.entries()) { int animIndex = 0; if (e.value.current != null) { for (int i = 0; i < e.key.animations.size; i++) { final Animation animation = e.key.animations.get(i); if (e.value.current.animation == animation) { animIndex = i; break; } } } animIndex = (animIndex + 1) % (e.key.animations.size + 1); e.value.animate((animIndex == e.key.animations.size) ? null : e.key.animations.get(animIndex).id, -1, 1f, null, 0.2f); } }
protected void switchAnimation () { for (ObjectMap.Entry<ModelInstance, AnimationController> e : animationControllers.entries()) { int animIndex = 0; if (e.value.current != null) { for (int i = 0; i < e.key.animations.size; i++) { final Animation animation = e.key.animations.get(i); if (e.value.current.animation == animation) { animIndex = i; break; } } } animIndex = (animIndex + 1) % e.key.animations.size; e.value.animate(e.key.animations.get(animIndex).id, -1, 1f, null, 0.2f); } }
protected void switchAnimation () { for (ObjectMap.Entry<ModelInstance, AnimationController> e : animationControllers.entries()) { int animIndex = 0; if (e.value.current != null) { for (int i = 0; i < e.key.animations.size; i++) { final Animation animation = e.key.animations.get(i); if (e.value.current.animation == animation) { animIndex = i; break; } } } animIndex = (animIndex + 1) % e.key.animations.size; e.value.animate(e.key.animations.get(animIndex).id, -1, 1f, null, 0.2f); } }
/** 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 (paused) return; 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; final float remain = current.update(delta); if (remain != 0f && queued != null) { inAction = false; animate(queued, queuedTransitionTime); queued = null; update(remain); return; } if (previous != null) applyAnimations(previous.animation, previous.offset + previous.time, current.animation, current.offset + current.time, transitionCurrentTime / transitionTargetTime); else applyAnimation(current.animation, current.offset + current.time); }