본문 바로가기
LibGdx

AnimationController class

by ses jeon 2021. 4. 9.
/** Class to control one or more {@link Animation}s on a {@link ModelInstance}. 
{ @link ModelInstance} 에서 하나 이상의 { @link Animation} 을 제어하는 ​​클래스 입니다.
Use the
 * {@link #setAnimation(String, int, float, AnimationListener)} method to change the current animation. Use the
 * { @link #setAnimation (String, int, float, AnimationListener)} 메서드를 사용하여 현재 애니메이션을 변경합니다.
 * {@link #animate(String, int, float, AnimationListener, float)} method to start an animation, optionally blending onto the
 * current animation. 
 * { @link #animate (String, int, float, AnimationListener, float)} 메서드를 사용하여 애니메이션을 시작하고 선택적으로
 * 현재 애니메이션.
 Use the {@link #queue(String, int, float, AnimationListener, float)} method to queue an animation to be
 * played when the current animation is finished. 
 { @link #queue (String, int, float, AnimationListener, float)} 메서드를 사용하여 애니메이션을
 * 현재 애니메이션이 끝나면 재생됩니다.
 Use the {@link #action(String, int, float, AnimationListener, float)} method to
 * play a (short) animation on top of the current animation.
 { @link #action (String, int, float, AnimationListener, float)} 메서드를 사용하여
 * 현재 애니메이션 위에 (짧은) 애니메이션을 재생합니다.
 * 
 * You can use multiple AnimationControllers on the same ModelInstance, as long as they don't interfere with each other (don't
 * affect the same {@link Node}s).
 * 서로 간섭하지 않는 한 동일한 odelInstance에서 여러 AnimationController를 사용할 수 있습니다 (같은 {@link Node}에 * 영향을주지 않음). 

* @author Xoppa */
public class AnimationController extends BaseAnimationController {

	/** Listener that will be informed when an animation is looped or completed.
    애니메이션이 반복되거나 완료 될 때 알림을받을 리스너입니다. 
	 * @author Xoppa */
	public interface AnimationListener {
		/** Gets called when an animation is completed.
		 * @param animation The animation which just completed. 
         애니메이션이 완료되면 호출됩니다. * @param animation 방금 완성한 애니메이션. 
         */
		void onEnd (final AnimationDesc animation);

		/** Gets called when an animation is looped. The {@link AnimationDesc#loopCount} is updated prior to this call and can be
		 * read or written to alter the number of remaining loops.
		 * @param animation The animation which just looped. 
         애니메이션이 반복 될 때 호출됩니다. {@link AnimationDesc # loopCount}는이 호출 전에 업데이트되며 
         나머지 루프 수를 변경하기 위해 * 읽거나 쓸 수 있습니다. * @param animation 방금 반복 한 애니메이션. 
         */
		void onLoop (final AnimationDesc animation);
	}

	/** Class describing how to play and {@link Animation}. You can read the values within this class to get the progress of the
	 * animation. Do not change the values. Only valid when the animation is currently played.
	 * @author Xoppa 
     게임 방법 및 {@link Animation}을 설명하는 수업입니다. 이 클래스 내의 값을 읽어 애니메이션의 진행 상황을 확인할 수 있습니다. 
     값을 변경하지 마십시오. 애니메이션이 현재 재생중인 경우에만 유효합니다. 
     */
	public static class AnimationDesc {
		/** Listener which will be informed when the animation is looped or ended. 
        애니메이션이 반복되거나 종료 될 때 알림을받을 리스너입니다. 
        */
		public AnimationListener listener;
		/** The animation to be applied. 적용 할 애니메이션입니다.  */
		public Animation animation;
		/** The speed at which to play the animation (can be negative), 1.0 for normal speed. 
        애니메이션 재생 속도 (음수 일 수 있음), 일반 속도의 경우 1.0입니다. 
        */
		public float speed;
		/** The current animation time. 
        현재 애니메이션 시간입니다. 
        */
		public float time;
		/** The offset within the animation (animation time = offsetTime + time) 
        애니메이션 내의 오프셋 (애니메이션 시간 = offsetTime + 시간) 
        */
		public float offset;
		/** The duration of the animation 애니메이션 기간 */
		public float duration;
		/** The number of remaining loops, negative for continuous, zero if stopped. 
        나머지 루프의 수, 연속의 경우 음수, 중지 된 경우 0입니다. 
        */
		public int loopCount;

		protected AnimationDesc () {
		}

		/** @return the remaining time or 0 if still animating. 
        @ 남은 시간을 반환하거나 여전히 애니메이션중인 경우 0을 반환합니다. */
		protected float update (float delta) {
			if (loopCount != 0 && animation != null) {
				int loops;
				final float diff = speed * delta;
				if (!MathUtils.isZero(duration)) {
					time += diff;
					loops = (int)Math.abs(time / duration);
					if (time < 0f) {
						loops++;
						while (time < 0f)
							time += duration;
					}
					time = Math.abs(time % duration);
				} else
					loops = 1;
				for (int i = 0; i < loops; i++) {
					if (loopCount > 0) loopCount--;
					if (loopCount != 0 && listener != null) listener.onLoop(this);
					if (loopCount == 0) {
						final float result = ((loops - 1) - i) * duration + (diff < 0f ? duration - time : time);
						time = (diff < 0f) ? 0f : duration;
						if (listener != null) listener.onEnd(this);
						return result;
					}
				}
				return 0f;
			} else
				return delta;
		}
	}

	protected final Pool<AnimationDesc> animationPool = new Pool<AnimationDesc>() {
		@Override
		protected AnimationDesc newObject () {
			return new AnimationDesc();
		}
	};

	/** The animation currently playing. Do not alter this value. 
    현재 재생중인 애니메이션입니다. 이 값을 변경하지 마십시오. 
    */
	public AnimationDesc current;
	/** The animation queued to be played when the {@link #current} animation is completed. Do not alter this value. 
    {@link #current} 애니메이션이 완료되면 재생 대기중인 애니메이션입니다. 이 값을 변경하지 마십시오. 
    */
	public AnimationDesc queued;
	/** The transition time which should be applied to the queued animation. Do not alter this value. 
    대기중인 애니메이션에 적용해야하는 전환 시간입니다. 이 값을 변경하지 마십시오. 
    */
	public float queuedTransitionTime;
	/** The animation which previously played. Do not alter this value. 
    이전에 재생 한 애니메이션입니다. 이 값을 변경하지 마십시오. 
    */
	public AnimationDesc previous;
	/** The current transition time. Do not alter this value. 
    현재 전환 시간입니다. 이 값을 변경하지 마십시오.
    */
	public float transitionCurrentTime;
	/** The target transition time. Do not alter this value. 
    목표 전환 시간. 이 값을 변경하지 마십시오. 
    */
	public float transitionTargetTime;
	/** Whether an action is being performed. Do not alter this value. 
    조치가 수행되고 있는지 여부. 이 값을 변경하지 마십시오. 
    */
	public boolean inAction;
	/** When true a call to {@link #update(float)} will not be processed. 
    true이면 {@link #update (float)}에 대한 호출이 처리되지 않습니다. 
    */
	public boolean paused;
	/** Whether to allow the same animation to be played while playing that animation. 
    해당 애니메이션을 재생하는 동안 동일한 애니메이션을 재생할 수 있는지 여부입니다. 
    */
	public boolean allowSameAnimation;

	private boolean justChangedAnimation = false;

	/** Construct a new AnimationController.
	 * @param target The {@link ModelInstance} on which the animations will be performed. 
     새로운 AnimationController를 생성합니다. @param target 애니메이션이 수행 될 {@link ModelInstance}입니다. 
     */
	public AnimationController (final ModelInstance target) {
		super(target);
	}

	private AnimationDesc obtain (final Animation anim, float offset, float duration, int loopCount, float speed,
		final AnimationListener listener) {
		if (anim == null) return null;
		final AnimationDesc result = animationPool.obtain();
		result.animation = anim;
		result.listener = listener;
		result.loopCount = loopCount;
		result.speed = speed;
		result.offset = offset;
		result.duration = duration < 0 ? (anim.duration - offset) : duration;
		result.time = speed < 0 ? result.duration : 0.f;
		return result;
	}

	private AnimationDesc obtain (final String id, float offset, float duration, 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);
		return obtain(anim, offset, duration, loopCount, speed, listener);
	}

	private AnimationDesc obtain (final AnimationDesc anim) {
		return obtain(anim.animation, anim.offset, anim.duration, anim.loopCount, anim.speed, anim.listener);
	}

	/** Update any animations currently being played.
	 * @param delta The time elapsed since last update, change this to alter the overall speed (can be negative). 
     현재 재생중인 애니메이션을 업데이트합니다.
* @param delta 마지막 업데이트 이후 경과 된 시간입니다. 전체 속도를 변경하려면이 값을 변경하십시오 (음수 일 수 있음). 
     */
	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);
	}

	/** Set the active animation, replacing any current animation.
	 * @param id The ID of the {@link Animation} within the {@link ModelInstance}.
	 * @return The {@link AnimationDesc} which can be read to get the progress of the animation. Will be invalid when the animation
	 *         is completed. 
     현재 애니메이션을 대체하여 활성 애니메이션을 설정합니다.
* @param id {@link ModelInstance} 내 {@link Animation}의 ID입니다.
* @return 애니메이션 진행률을 얻기 위해 읽을 수있는 {@link AnimationDesc}입니다. 애니메이션이 완료되면 무효가됩니다. 
     
     */
	public AnimationDesc setAnimation (final String id) {
		return setAnimation(id, 1, 1.0f, null);
	}

	/** Set the active animation, replacing any current animation.
	 * @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.
	 * @return The {@link AnimationDesc} which can be read to get the progress of the animation. Will be invalid when the animation
	 *         is completed. 
     현재 애니메이션을 대체하여 활성 애니메이션을 설정합니다.
* @param id {@link ModelInstance} 내 {@link Animation}의 ID입니다.
* @param loopCount 애니메이션을 반복하는 횟수, 애니메이션을 한 번만 재생하려면 0, 애니메이션을 계속 반복하려면 음수입니다.
* @return 애니메이션 진행률을 얻기 위해 읽을 수있는 {@link AnimationDesc}입니다. 애니메이션이 완료되면 무효가됩니다. 
     
     */
	public AnimationDesc setAnimation (final String id, int loopCount) {
		return setAnimation(id, loopCount, 1.0f, null);
	}

	/** Set the active animation, replacing any current animation.
	 * @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.
	 * @return The {@link AnimationDesc} which can be read to get the progress of the animation. Will be invalid when the animation
	 *         is completed. 
     현재 애니메이션을 대체하여 활성 애니메이션을 설정합니다.
* @param id {@link ModelInstance} 내 {@link Animation}의 ID입니다.
* @param listener 애니메이션이 반복되거나 완료 될 때 알림을받을 {@link AnimationListener}입니다.
* @return 애니메이션 진행률을 얻기 위해 읽을 수있는 {@link AnimationDesc}입니다. 애니메이션이 완료되면 무효가됩니다. 
     
     */
	public AnimationDesc setAnimation (final String id, final AnimationListener listener) {
		return setAnimation(id, 1, 1.0f, listener);
	}

	/** Set the active animation, replacing any current animation.
	 * @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.
	 * @return The {@link AnimationDesc} which can be read to get the progress of the animation. Will be invalid when the animation
	 *         is completed. 
     현재 애니메이션을 대체하여 활성 애니메이션을 설정합니다.
* @param id {@link ModelInstance} 내 {@link Animation}의 ID입니다.
* @param loopCount 애니메이션을 반복하는 횟수, 애니메이션을 한 번만 재생하려면 0, 연속적으로 재생하려면 음수
* 애니메이션을 반복합니다.
* @param listener 애니메이션이 반복되거나 완료 될 때 알림을받을 {@link AnimationListener}입니다.
* @return 애니메이션 진행률을 얻기 위해 읽을 수있는 {@link AnimationDesc}입니다. 애니메이션이 완료되면 무효가됩니다. 
     */
	public AnimationDesc setAnimation (final String id, int loopCount, final AnimationListener listener) {
		return setAnimation(id, loopCount, 1.0f, listener);
	}

	/** Set the active animation, replacing any current animation.
	 * @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.
	 * @return The {@link AnimationDesc} which can be read to get the progress of the animation. Will be invalid when the animation
	 *         is completed. 
     현재 애니메이션을 대체하여 활성 애니메이션을 설정합니다.
* @param id {@link ModelInstance} 내 {@link Animation}의 ID입니다.
* @param loopCount 애니메이션을 반복하는 횟수, 애니메이션을 한 번만 재생하려면 0, 연속적으로 재생하려면 음수
* 애니메이션을 반복합니다.
* @param speed 애니메이션이 재생되어야하는 속도. 기본값은 1.0f입니다. 2.0f 값은 다음 위치에서 애니메이션을 재생합니다.
* 정상 속도의 두 배, 0.5f 값은 정상 속도의 절반 등으로 애니메이션을 재생합니다.이 값은
* 네거티브, 애니메이션이 반대로 재생됩니다. 이 값은 0이 될 수 없습니다.
* @param listener 애니메이션이 반복되거나 완료 될 때 알림을받을 {@link AnimationListener}입니다.
* @return 애니메이션 진행률을 얻기 위해 읽을 수있는 {@link AnimationDesc}입니다. 애니메이션이 완료되면 무효가됩니다. 
     
     */
	public AnimationDesc setAnimation (final String id, int loopCount, float speed, final AnimationListener listener) {
		return setAnimation(id, 0f, -1f, loopCount, speed, listener);
	}

	/** Set the active animation, replacing any current animation.
	 * @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.
	 * @return The {@link AnimationDesc} which can be read to get the progress of the animation. Will be invalid when the animation
	 *         is completed. 
     현재 애니메이션을 대체하여 활성 애니메이션을 설정합니다.
* @param id {@link ModelInstance} 내 {@link Animation}의 ID입니다.
* @param offset 애니메이션 시작까지의 오프셋 (초)입니다.
* @param duration 애니메이션의 지속 시간 (초)입니다 (또는 애니메이션이 끝날 때까지 재생하려면 음수).
* @param loopCount 애니메이션을 반복하는 횟수, 애니메이션을 한 번만 재생하려면 0, 연속적으로 재생하려면 음수
* 애니메이션을 반복합니다.
* @param speed 애니메이션이 재생되어야하는 속도. 기본값은 1.0f입니다. 2.0f 값은 다음 위치에서 애니메이션을 재생합니다.
* 정상 속도의 두 배, 0.5f 값은 정상 속도의 절반 등으로 애니메이션을 재생합니다.이 값은
* 부정적, 애니메이션이 역으로 재생됩니다. 이 값은 0이 될 수 없습니다.
* @param listener 애니메이션이 반복되거나 완료 될 때 알림을받을 {@link AnimationListener}입니다.
* @return 애니메이션 진행률을 얻기 위해 읽을 수있는 {@link AnimationDesc}입니다. 애니메이션이 완료되면 무효가됩니다. 
     
     */
	public AnimationDesc setAnimation (final String id, float offset, float duration, int loopCount, float speed,
		final AnimationListener listener) {
		return setAnimation(obtain(id, offset, duration, loopCount, speed, listener));
	}

	/** Set the active animation, replacing any current animation. 
    현재 애니메이션을 대체하여 활성 애니메이션을 설정합니다. 
    */
	protected AnimationDesc setAnimation (final Animation anim, float offset, float duration, int loopCount, float speed,
		final AnimationListener listener) {
		return setAnimation(obtain(anim, offset, duration, loopCount, speed, listener));
	}

	/** Set the active animation, replacing any current animation. 
    현재 애니메이션을 대체하여 활성 애니메이션을 설정합니다. 
    */
	protected AnimationDesc setAnimation (final AnimationDesc anim) {
		if (current == null)
			current = anim;
		else {
			if (!allowSameAnimation && anim != null && current.animation == anim.animation)
				anim.time = current.time;
			else
				removeAnimation(current.animation);
			animationPool.free(current);
			current = anim;
		}
		justChangedAnimation = true;
		return anim;
	}

	/** 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. 
     전환 시간 동안 기존 애니메이션 위에 새 애니메이션을 혼합하여 현재 애니메이션을 변경합니다.
* @param id {@link ModelInstance} 내 {@link Animation}의 ID입니다.
* @param transitionTime 현재 재생중인 애니메이션 (있는 경우) 위에 새 애니메이션을 전환하는 데 걸리는 시간입니다.
* @return 애니메이션 진행률을 얻기 위해 읽을 수있는 {@link AnimationDesc}입니다. 애니메이션이 완료되면 무효가됩니다. 
     */
	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. 
     전환 시간 동안 기존 애니메이션 위에 새 애니메이션을 혼합하여 현재 애니메이션을 변경합니다.
* @param id {@link ModelInstance} 내 {@link Animation}의 ID입니다.
* @param listener 애니메이션이 반복되거나 완료 될 때 알림을받을 {@link AnimationListener}입니다.
* @param transitionTime 현재 재생중인 애니메이션 (있는 경우) 위에 새 애니메이션을 전환하는 데 걸리는 시간입니다.
* @return 애니메이션 진행률을 얻기 위해 읽을 수있는 {@link AnimationDesc}입니다. 애니메이션이 완료되면 무효가됩니다. 
     */
	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. 
     전환 시간 동안 기존 애니메이션 위에 새 애니메이션을 혼합하여 현재 애니메이션을 변경합니다.
* @param id {@link ModelInstance} 내 {@link Animation}의 ID입니다.
* @param loopCount 애니메이션을 반복하는 횟수, 애니메이션을 한 번만 재생하려면 0, 연속적으로 재생하려면 음수
* 애니메이션을 반복합니다.
* @param listener 애니메이션이 반복되거나 완료 될 때 알림을받을 {@link AnimationListener}입니다.
* @param transitionTime 현재 재생중인 애니메이션 (있는 경우) 위에 새 애니메이션을 전환하는 데 걸리는 시간입니다.
* @return 애니메이션 진행률을 얻기 위해 읽을 수있는 {@link AnimationDesc}입니다. 애니메이션이 완료되면 무효가됩니다. 
     */
	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 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. 
     전환 시간 동안 기존 애니메이션 위에 새 애니메이션을 혼합하여 현재 애니메이션을 변경합니다.
* @param id {@link ModelInstance} 내 {@link Animation}의 ID입니다.
* @param loopCount 애니메이션을 반복하는 횟수, 애니메이션을 한 번만 재생하려면 0, 애니메이션을 계속 반복하려면 음수입니다.
* @param speed 애니메이션이 재생되어야하는 속도. 기본값은 1.0f입니다. 2.0f 값은 애니메이션을 정상 속도의 두 배로 재생하고 0.5f 값은 정상 속도의 절반으로 애니메이션을 재생합니다.이 값은 음수 일 수 있으므로 애니메이션이 역방향으로 재생됩니다. 이 값은 0이 될 수 없습니다.
* @param listener 애니메이션이 반복되거나 완료 될 때 알림을받을 {@link AnimationListener}입니다.
* @param transitionTime 현재 재생중인 애니메이션 (있는 경우) 위에 새 애니메이션을 전환하는 데 걸리는 시간입니다.
* @return 애니메이션 진행률을 얻기 위해 읽을 수있는 {@link AnimationDesc}입니다. 애니메이션이 완료되면 무효가됩니다. 
     */
	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 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. 
     전환 시간 동안 기존 애니메이션 위에 새 애니메이션을 혼합하여 현재 애니메이션을 변경합니다.
* @param id {@link ModelInstance} 내 {@link Animation}의 ID입니다.
* @param offset 애니메이션 시작까지의 오프셋 (초)입니다.
* @param duration 애니메이션의 지속 시간 (초)입니다 (또는 애니메이션이 끝날 때까지 재생하려면 음수).
* @param loopCount 애니메이션을 반복하는 횟수, 애니메이션을 한 번만 재생하려면 0, 애니메이션을 계속 반복하려면 음수입니다.
* @param speed 애니메이션이 재생되어야하는 속도. 기본값은 1.0f입니다. 2.0f 값은 애니메이션을 정상 속도의 두 배로 재생하고 0.5f 값은 정상 속도의 절반으로 애니메이션을 재생합니다.이 값은 음수 일 수 있으므로 애니메이션이 역방향으로 재생됩니다. 이 값은 0이 될 수 없습니다.
* @param listener 애니메이션이 반복되거나 완료 될 때 알림을받을 {@link AnimationListener}입니다.
* @param transitionTime 현재 재생중인 애니메이션 (있는 경우) 위에 새 애니메이션을 전환하는 데 걸리는 시간입니다.
* @return 애니메이션 진행률을 얻기 위해 읽을 수있는 {@link AnimationDesc}입니다. 애니메이션이 완료되면 무효가됩니다. 
     
     */
	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. 
    전환 시간 동안 기존 애니메이션 위에 새 애니메이션을 혼합하여 현재 애니메이션을 변경합니다. 
    */
	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. 
    전환 시간 동안 기존 애니메이션 위에 새 애니메이션을 혼합하여 현재 애니메이션을 변경합니다. 
    */
	protected AnimationDesc animate (final AnimationDesc anim, float transitionTime) {
		if (current == null)
			current = anim;
		else if (inAction)
			queue(anim, transitionTime);
		else if (!allowSameAnimation && anim != null && current.animation == anim.animation) {
			anim.time = current.time;
			animationPool.free(current);
			current = anim;
		} else {
			if (previous != null) {
				removeAnimation(previous.animation);
				animationPool.free(previous);
			}
			previous = current;
			current = anim;
			transitionCurrentTime = 0f;
			transitionTargetTime = transitionTime;
		}
		return anim;
	}

	/** Queue an animation to be applied when the {@link #current} animation is finished. If the current animation is continuously
	 * looping it will be synchronized on next loop.
	 * @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. 
     {@link #current} 애니메이션이 완료되면 적용 할 애니메이션을 대기열에 추가합니다. 현재 애니메이션이 계속 반복되는 경우 다음 루프에서 동기화됩니다.
* @param id {@link ModelInstance} 내 {@link Animation}의 ID입니다.
* @param loopCount 애니메이션을 반복하는 횟수, 애니메이션을 한 번만 재생하려면 0, 애니메이션을 계속 반복하려면 음수입니다.
* @param speed 애니메이션이 재생되어야하는 속도. 기본값은 1.0f입니다. 2.0f 값은 애니메이션을 정상 속도의 두 배로 재생하고 0.5f 값은 정상 속도의 절반으로 애니메이션을 재생합니다.이 값은 음수 일 수 있으므로 애니메이션이 역방향으로 재생됩니다. 이 값은 0이 될 수 없습니다.
* @param listener 애니메이션이 반복되거나 완료 될 때 알림을받을 {@link AnimationListener}입니다.
* @param transitionTime 현재 재생중인 애니메이션 (있는 경우) 위에 새 애니메이션을 전환하는 데 걸리는 시간입니다.
* @return 애니메이션 진행률을 얻기 위해 읽을 수있는 {@link AnimationDesc}입니다. 애니메이션이 완료되면 무효가됩니다. 
     */
	public AnimationDesc queue (final String id, int loopCount, float speed, final AnimationListener listener, float transitionTime) {
		return queue(id, 0f, -1f, loopCount, speed, listener, transitionTime);
	}

	/** Queue an animation to be applied when the {@link #current} animation is finished. If the current animation is continuously
	 * looping it will be synchronized on next loop.
	 * @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. 
     {@link #current} 애니메이션이 완료되면 적용 할 애니메이션을 대기열에 추가합니다. 현재 애니메이션이 계속 반복되는 경우 다음 루프에서 동기화됩니다.
* @param id {@link ModelInstance} 내 {@link Animation}의 ID입니다.
* @param offset 애니메이션 시작까지의 오프셋 (초)입니다.
* @param duration 애니메이션의 지속 시간 (초)입니다 (또는 애니메이션이 끝날 때까지 재생하려면 음수).
* @param loopCount 애니메이션을 반복하는 횟수, 애니메이션을 한 번만 재생하려면 0, 애니메이션을 계속 반복하려면 음수입니다.
* @param speed 애니메이션이 재생되어야하는 속도. 기본값은 1.0f입니다. 2.0f 값은 애니메이션을 정상 속도의 두 배로 재생하고 0.5f 값은 정상 속도의 절반으로 애니메이션을 재생합니다.이 값은 음수 일 수 있으므로 애니메이션이 역방향으로 재생됩니다. 이 값은 0이 될 수 없습니다.
* @param listener 애니메이션이 반복되거나 완료 될 때 알림을받을 {@link AnimationListener}입니다.
* @param transitionTime 현재 재생중인 애니메이션 (있는 경우) 위에 새 애니메이션을 전환하는 데 걸리는 시간입니다.
* @return 애니메이션 진행률을 얻기 위해 읽을 수있는 {@link AnimationDesc}입니다. 애니메이션이 완료되면 무효가됩니다. 
     */
	public AnimationDesc queue (final String id, float offset, float duration, int loopCount, float speed,
		final AnimationListener listener, float transitionTime) {
		return queue(obtain(id, 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 Animation anim, float offset, float duration, int loopCount, float speed,
		final AnimationListener listener, float transitionTime) {
		return queue(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;
	}

	/** Apply an action animation on top of the current animation.
	 * @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. 
     현재 애니메이션 위에 액션 애니메이션을 적용합니다.
* @param id {@link ModelInstance} 내 {@link Animation}의 ID입니다.
* @param loopCount 애니메이션을 반복하는 횟수, 애니메이션을 한 번만 재생하려면 0, 애니메이션을 계속 반복하려면 음수입니다.
* @param speed 애니메이션이 재생되어야하는 속도. 기본값은 1.0f입니다. 2.0f 값은 애니메이션을 정상 속도의 두 배로 재생하고 0.5f 값은 정상 속도의 절반으로 애니메이션을 재생합니다.이 값은 음수 일 수 있으므로 애니메이션이 역방향으로 재생됩니다. 이 값은 0이 될 수 없습니다.
* @param listener 애니메이션이 반복되거나 완료 될 때 알림을받을 {@link AnimationListener}입니다.
* @param transitionTime 현재 재생중인 애니메이션 (있는 경우) 위에 새 애니메이션을 전환하는 데 걸리는 시간입니다.
* @return 애니메이션 진행률을 얻기 위해 읽을 수있는 {@link AnimationDesc}입니다. 애니메이션이 완료되면 무효가됩니다. 
     */
	public AnimationDesc action (final String id, int loopCount, float speed, final AnimationListener listener,
		float transitionTime) {
		return action(id, 0, -1f, loopCount, speed, listener, transitionTime);
	}

	/** Apply an action animation on top of the current animation.
	 * @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. 
     현재 애니메이션 위에 액션 애니메이션을 적용합니다.
* @param id {@link ModelInstance} 내 {@link Animation}의 ID입니다.
* @param offset 애니메이션 시작까지의 오프셋 (초)입니다.
* @param duration 애니메이션의 지속 시간 (초)입니다 (또는 애니메이션이 끝날 때까지 재생하려면 음수).
* @param loopCount 애니메이션을 반복하는 횟수, 애니메이션을 한 번만 재생하려면 0, 애니메이션을 계속 반복하려면 음수입니다.
* @param speed 애니메이션이 재생되어야하는 속도. 기본값은 1.0f입니다. 2.0f 값은 애니메이션을 정상 속도의 두 배로 재생하고 0.5f 값은 정상 속도의 절반으로 애니메이션을 재생합니다.이 값은 음수 일 수 있으므로 애니메이션이 역방향으로 재생됩니다. 이 값은 0이 될 수 없습니다.
* @param listener 애니메이션이 반복되거나 완료 될 때 알림을받을 {@link AnimationListener}입니다.
* @param transitionTime 현재 재생중인 애니메이션 (있는 경우) 위에 새 애니메이션을 전환하는 데 걸리는 시간입니다.
* @return 애니메이션 진행률을 얻기 위해 읽을 수있는 {@link AnimationDesc}입니다. 애니메이션이 완료되면 무효가됩니다. 
     */
	public AnimationDesc action (final String id, float offset, float duration, int loopCount, float speed,
		final AnimationListener listener, float transitionTime) {
		return action(obtain(id, offset, duration, loopCount, speed, listener), transitionTime);
	}

	/** Apply an action animation on top of the current animation. 
    현재 애니메이션 위에 액션 애니메이션을 적용합니다. 
    */
	protected AnimationDesc action (final Animation anim, float offset, float duration, int loopCount, float speed,
		final AnimationListener listener, float transitionTime) {
		return action(obtain(anim, 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;
	}
}

댓글