* \r
*/\r
public abstract class Action {\r
+\r
protected OnActionCompleted listener = null;\r
- \r
+\r
/**\r
* Sets the {@link Actor} of this action. Will be called when the Action is added to an Actor via {@link Actor#action(Action)}\r
* before any other call to this interface.\r
/**\r
* Called by the owner of the action when it can release all its resources, e.g. put itself back into a pool.\r
*/\r
- public abstract void finish ();\r
+ public void finish () {\r
+ if (listener != null) {\r
+ listener.completed(this);\r
+ }\r
+ }\r
\r
/**\r
* Creates a copy of this action. The action must be in a state independent of the original and one must be able to call\r
* {@link #setTarget(Actor)} on it without any side effects.\r
*/\r
public abstract Action copy ();\r
- \r
+\r
/**\r
* Sets the listener to be invoked when the action is finished.\r
* @param listener\r
* @return this\r
*/\r
- public Action setCompletionListener(OnActionCompleted listener) {\r
+ public Action setCompletionListener (OnActionCompleted listener) {\r
this.listener = listener;\r
return this;\r
}\r
public OnActionCompleted getCompletionListener () {\r
return listener;\r
}\r
+\r
}\r
--- /dev/null
+/*\r
+ * Copyright 2011 Moritz Post (moritzpost@gmail.com)\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the\r
+ * License. You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"\r
+ * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+\r
+package com.badlogic.gdx.scenes.scene2d;\r
+\r
+/**\r
+ * An {@link AnimationAction} performs a transformation on its target {@link Actor}. These transformations physically change the\r
+ * Actor itself.\r
+ * \r
+ * @author Moritz Post <moritzpost@gmail.com>\r
+ */\r
+public abstract class AnimationAction extends Action {\r
+\r
+ protected float duration;\r
+ protected float invDuration;\r
+ protected float taken;\r
+ protected Actor target;\r
+ protected boolean done;\r
+\r
+ private Interpolator interpolator;\r
+\r
+ @Override public boolean isDone () {\r
+ return done;\r
+ }\r
+\r
+ @Override public void finish () {\r
+ super.finish();\r
+ if (interpolator != null) {\r
+ interpolator.finished();\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Sets an {@link Interpolator} to modify the progression of the animations.\r
+ * \r
+ * @param interpolator the interpolator to use during the animation\r
+ * @return an instance of self so that the call can be easily chained\r
+ */\r
+ public AnimationAction setInterpolator (Interpolator interpolator) {\r
+ this.interpolator = interpolator;\r
+ return this;\r
+ }\r
+\r
+ protected float createInterpolatedAlpha (float delta) {\r
+ taken += delta;\r
+ if (taken >= duration) {\r
+ taken = duration;\r
+ done = true;\r
+ return taken;\r
+ } else if (interpolator == null) {\r
+ return taken * invDuration;\r
+ } else {\r
+ float interpolatedTime = interpolator.getInterpolation(taken / duration) * duration;\r
+ return interpolatedTime * invDuration;\r
+ }\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright 2011 Moritz Post (moritzpost@gmail.com)\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the\r
+ * License. You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"\r
+ * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+\r
+package com.badlogic.gdx.scenes.scene2d;\r
+\r
+/**\r
+ * An interpolator defines the rate of change of an animation. This allows the basic animation effects (alpha, scale, translate,\r
+ * rotate) to be accelerated, decelerated etc.\r
+ * \r
+ * @author Moritz Post <moritzpost@gmail.com>\r
+ */\r
+public interface Interpolator {\r
+\r
+ /**\r
+ * Maps a point in the animation duration to a multiplier to be applied to the transformations of an animation. The Input is a\r
+ * percentage of the elapsed animation duration.\r
+ * \r
+ * @param input A value between 0 and 1.0 indicating our current point in the animation where 0 represents the start and 1.0\r
+ * represents the end\r
+ * @return The interpolation value. This value can be more than 1.0 for {@link Interpolator}s which overshoot their targets, or\r
+ * less than 0 for {@link Interpolator}s that undershoot their targets.\r
+ */\r
+ float getInterpolation (float input);\r
+\r
+ /**\r
+ * Called when the animation has finished and the {@link Interpolator} is no longer needed.\r
+ */\r
+ void finished ();\r
+\r
+}\r
/*\r
- * Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)\r
+ * Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com), Moritz Post\r
+ * (moritzpost@gmail.com)\r
* \r
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the\r
* License. You may obtain a copy of the License at\r
\r
import com.badlogic.gdx.scenes.scene2d.Action;\r
import com.badlogic.gdx.scenes.scene2d.Actor;\r
+import com.badlogic.gdx.scenes.scene2d.AnimationAction;\r
import com.badlogic.gdx.utils.Pool;\r
\r
-public class FadeIn extends Action {\r
- static final Pool<FadeIn> pool = new Pool<FadeIn>(4, 100) {\r
- protected FadeIn newObject () {\r
+public class FadeIn extends AnimationAction {\r
+\r
+ private static final Pool<FadeIn> pool = new Pool<FadeIn>(4, 100) {\r
+ @Override protected FadeIn newObject () {\r
return new FadeIn();\r
}\r
};\r
\r
protected float startAlpha = 0;\r
protected float deltaAlpha = 0;\r
- protected float duration;\r
- protected float invDuration;\r
- protected float taken = 0;\r
- protected Actor target;\r
- protected boolean done;\r
\r
public static FadeIn $ (float duration) {\r
FadeIn action = pool.obtain();\r
this.deltaAlpha = 1;\r
this.taken = 0;\r
this.done = false;\r
- \r
+\r
}\r
\r
@Override public void act (float delta) {\r
- taken += delta;\r
- if (taken >= duration) {\r
- taken = duration;\r
- done = true;\r
+ float alpha = createInterpolatedAlpha(delta);\r
+ if (done) {\r
+ target.color.a = 1.0f;\r
+ } else {\r
+ target.color.a = startAlpha + deltaAlpha * alpha;\r
}\r
-\r
- float alpha = taken * invDuration;\r
- target.color.a = startAlpha + deltaAlpha * alpha;\r
- }\r
-\r
- @Override public boolean isDone () {\r
- return done;\r
}\r
\r
@Override public void finish () {\r
pool.free(this);\r
- if(listener != null)\r
+ if (listener != null) {\r
listener.completed(this);\r
+ }\r
}\r
\r
@Override public Action copy () {\r
/*\r
- * Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)\r
+ * Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com), Moritz Post\r
+ * (moritzpost@gmail.com)\r
* \r
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the\r
* License. You may obtain a copy of the License at\r
\r
import com.badlogic.gdx.scenes.scene2d.Action;\r
import com.badlogic.gdx.scenes.scene2d.Actor;\r
+import com.badlogic.gdx.scenes.scene2d.AnimationAction;\r
import com.badlogic.gdx.utils.Pool;\r
\r
-public class FadeOut extends Action {\r
- static final Pool<FadeOut> pool = new Pool<FadeOut>(4, 100) {\r
- protected FadeOut newObject () {\r
+public class FadeOut extends AnimationAction {\r
+\r
+ private static final Pool<FadeOut> pool = new Pool<FadeOut>(4, 100) {\r
+ @Override protected FadeOut newObject () {\r
return new FadeOut();\r
}\r
};\r
\r
protected float startAlpha = 0;\r
protected float deltaAlpha = 0;\r
- protected float duration;\r
- protected float invDuration;\r
- protected float taken = 0;\r
- protected Actor target;\r
- protected boolean done;\r
\r
public static FadeOut $ (float duration) {\r
FadeOut action = pool.obtain();\r
}\r
\r
@Override public void act (float delta) {\r
- taken += delta;\r
- if (taken >= duration) {\r
- taken = duration;\r
- done = true;\r
+ float alpha = createInterpolatedAlpha(delta);\r
+ if (done) {\r
+ target.color.a = 0.0f;\r
+ } else {\r
+ target.color.a = startAlpha + deltaAlpha * alpha;\r
}\r
-\r
- float alpha = taken * invDuration;\r
- target.color.a = startAlpha + deltaAlpha * alpha;\r
- }\r
-\r
- @Override public boolean isDone () {\r
- return done;\r
}\r
\r
@Override public void finish () {\r
+ super.finish();\r
pool.free(this);\r
- if(listener != null)\r
- listener.completed(this);\r
}\r
\r
@Override public Action copy () {\r
/*\r
- * Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)\r
+ * Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com), Moritz Post\r
+ * (moritzpost@gmail.com)\r
* \r
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the\r
* License. You may obtain a copy of the License at\r
\r
import com.badlogic.gdx.scenes.scene2d.Action;\r
import com.badlogic.gdx.scenes.scene2d.Actor;\r
+import com.badlogic.gdx.scenes.scene2d.AnimationAction;\r
import com.badlogic.gdx.utils.Pool;\r
\r
-public class FadeTo extends Action {\r
- static final Pool<FadeTo> pool = new Pool<FadeTo>(4, 100) {\r
- protected FadeTo newObject () {\r
+public class FadeTo extends AnimationAction {\r
+\r
+ private static final Pool<FadeTo> pool = new Pool<FadeTo>(4, 100) {\r
+ @Override protected FadeTo newObject () {\r
return new FadeTo();\r
}\r
};\r
protected float toAlpha = 0;\r
protected float startAlpha;\r
protected float deltaAlpha = 0;\r
- protected float duration;\r
- protected float invDuration;\r
- protected float taken = 0;\r
- protected Actor target;\r
- protected boolean done;\r
\r
public static FadeTo $ (float alpha, float duration) {\r
FadeTo action = pool.obtain();\r
- if (alpha < 0) alpha = 0;\r
- if (alpha > 1) alpha = 1;\r
- action.toAlpha = alpha;\r
+ action.toAlpha = Math.min(Math.max(alpha, 0.0f), 1.0f);\r
action.duration = duration;\r
action.invDuration = 1 / duration;\r
action.listener = null;\r
}\r
\r
@Override public void act (float delta) {\r
- taken += delta;\r
- if (taken >= duration) {\r
- taken = duration;\r
- done = true;\r
+ float alpha = createInterpolatedAlpha(delta);\r
+ if (done) {\r
+ target.color.a = toAlpha;\r
+ } else {\r
+ float val = startAlpha + deltaAlpha * alpha;\r
+ target.color.a = Math.min(Math.max(val, 0.0f), 1.0f);\r
}\r
-\r
- float alpha = taken * invDuration;\r
- target.color.a = startAlpha + deltaAlpha * alpha;\r
- }\r
-\r
- @Override public boolean isDone () {\r
- return done;\r
}\r
\r
@Override public void finish () {\r
+ super.finish();\r
pool.free(this);\r
- if(listener != null)\r
- listener.completed(this);\r
}\r
\r
@Override public Action copy () {\r
/*\r
- * Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)\r
+ * Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com), Moritz Post\r
+ * (moritzpost@gmail.com)\r
* \r
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the\r
* License. You may obtain a copy of the License at\r
\r
import com.badlogic.gdx.scenes.scene2d.Action;\r
import com.badlogic.gdx.scenes.scene2d.Actor;\r
+import com.badlogic.gdx.scenes.scene2d.AnimationAction;\r
import com.badlogic.gdx.utils.Pool;\r
\r
-public class MoveBy extends Action {\r
- static final Pool<MoveBy> pool = new Pool<MoveBy>(4, 100) {\r
- protected MoveBy newObject () {\r
+public class MoveBy extends AnimationAction {\r
+\r
+ private static final Pool<MoveBy> pool = new Pool<MoveBy>(4, 100) {\r
+ @Override protected MoveBy newObject () {\r
return new MoveBy();\r
}\r
};\r
protected float startY;\r
protected float deltaX;\r
protected float deltaY;\r
- protected float duration;\r
- protected float invDuration;\r
- protected float taken = 0;\r
- protected Actor target;\r
- protected boolean done;\r
\r
public static MoveBy $ (float x, float y, float duration) {\r
MoveBy action = pool.obtain();\r
this.deltaX = x;\r
this.deltaY = y;\r
this.taken = 0;\r
- this.done = false; \r
+ this.done = false;\r
}\r
\r
@Override public void act (float delta) {\r
- taken += delta;\r
- if (taken >= duration) {\r
- taken = duration;\r
- done = true;\r
+ float alpha = createInterpolatedAlpha(delta);\r
+ if (done) {\r
+ target.x = x;\r
+ target.y = y;\r
+ } else {\r
+ target.x = startX + deltaX * alpha;\r
+ target.y = startY + deltaY * alpha;\r
}\r
-\r
- float alpha = taken * invDuration;\r
- target.x = startX + deltaX * alpha;\r
- target.y = startY + deltaY * alpha;\r
- }\r
-\r
- @Override public boolean isDone () {\r
- return done;\r
}\r
\r
@Override public void finish () {\r
+ super.finish();\r
pool.free(this);\r
- if(listener != null)\r
- listener.completed(this);\r
}\r
\r
@Override public Action copy () {\r
/*\r
- * Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)\r
+ * Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com), Moritz Post\r
+ * (moritzpost@gmail.com)\r
* \r
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the\r
* License. You may obtain a copy of the License at\r
\r
import com.badlogic.gdx.scenes.scene2d.Action;\r
import com.badlogic.gdx.scenes.scene2d.Actor;\r
+import com.badlogic.gdx.scenes.scene2d.AnimationAction;\r
import com.badlogic.gdx.utils.Pool;\r
\r
-public class MoveTo extends Action {\r
- static final Pool<MoveTo> pool = new Pool<MoveTo>(4, 100) {\r
- protected MoveTo newObject () {\r
+public class MoveTo extends AnimationAction {\r
+\r
+ private static final Pool<MoveTo> pool = new Pool<MoveTo>(4, 100) {\r
+ @Override protected MoveTo newObject () {\r
return new MoveTo();\r
}\r
};\r
protected float startY;\r
protected float deltaX;\r
protected float deltaY;\r
- protected float duration;\r
- protected float invDuration;\r
- protected float taken = 0;\r
- protected Actor target;\r
- protected boolean done;\r
\r
public static MoveTo $ (float x, float y, float duration) {\r
MoveTo action = pool.obtain();\r
}\r
\r
@Override public void act (float delta) {\r
- taken += delta;\r
- if (taken >= duration) {\r
- taken = duration;\r
- done = true;\r
+ float alpha = createInterpolatedAlpha(delta);\r
+ if (done) {\r
+ target.x = x;\r
+ target.y = y;\r
+ } else {\r
+ target.x = startX + deltaX * alpha;\r
+ target.y = startY + deltaY * alpha;\r
}\r
-\r
- float alpha = taken * invDuration;\r
- target.x = startX + deltaX * alpha;\r
- target.y = startY + deltaY * alpha;\r
- }\r
-\r
- @Override public boolean isDone () {\r
- return done;\r
}\r
\r
@Override public void finish () {\r
+ super.finish();\r
pool.free(this);\r
- if(listener != null)\r
- listener.completed(this);\r
}\r
\r
@Override public Action copy () {\r
/*\r
- * Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)\r
+ * Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com), Moritz Post\r
+ * (moritzpost@gmail.com)\r
* \r
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the\r
* License. You may obtain a copy of the License at\r
\r
import com.badlogic.gdx.scenes.scene2d.Action;\r
import com.badlogic.gdx.scenes.scene2d.Actor;\r
+import com.badlogic.gdx.scenes.scene2d.AnimationAction;\r
import com.badlogic.gdx.utils.Pool;\r
\r
-public class RotateBy extends Action {\r
- static final Pool<RotateBy> pool = new Pool<RotateBy>(4, 100) {\r
- protected RotateBy newObject () {\r
+public class RotateBy extends AnimationAction {\r
+\r
+ private static final Pool<RotateBy> pool = new Pool<RotateBy>(4, 100) {\r
+ @Override protected RotateBy newObject () {\r
return new RotateBy();\r
}\r
};\r
protected float rotation;\r
protected float startRotation;;\r
protected float deltaRotation;\r
- protected float duration;\r
- protected float invDuration;\r
- protected float taken = 0;\r
- protected Actor target;\r
- protected boolean done;\r
\r
public static RotateBy $ (float rotation, float duration) {\r
RotateBy action = pool.obtain();\r
}\r
\r
@Override public void act (float delta) {\r
- taken += delta;\r
- if (taken >= duration) {\r
- taken = duration;\r
- done = true;\r
- return;\r
+ float alpha = createInterpolatedAlpha(delta);\r
+ if (done) {\r
+ target.rotation = rotation;\r
+ } else {\r
+ target.rotation = startRotation + deltaRotation * alpha;\r
}\r
-\r
- float alpha = taken * invDuration;\r
- target.rotation = startRotation + deltaRotation * alpha;\r
- }\r
-\r
- @Override public boolean isDone () {\r
- return done;\r
}\r
\r
@Override public void finish () {\r
+ super.finish();\r
pool.free(this);\r
- if(listener != null)\r
- listener.completed(this);\r
}\r
\r
@Override public Action copy () {\r
/*\r
- * Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)\r
+ * Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com), Moritz Post\r
+ * (moritzpost@gmail.com)\r
* \r
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the\r
* License. You may obtain a copy of the License at\r
\r
import com.badlogic.gdx.scenes.scene2d.Action;\r
import com.badlogic.gdx.scenes.scene2d.Actor;\r
+import com.badlogic.gdx.scenes.scene2d.AnimationAction;\r
import com.badlogic.gdx.utils.Pool;\r
\r
-public class RotateTo extends Action {\r
- static final Pool<RotateTo> pool = new Pool<RotateTo>(4, 100) {\r
- protected RotateTo newObject () {\r
+public class RotateTo extends AnimationAction {\r
+\r
+ private static final Pool<RotateTo> pool = new Pool<RotateTo>(4, 100) {\r
+ @Override protected RotateTo newObject () {\r
return new RotateTo();\r
}\r
};\r
protected float rotation;\r
protected float startRotation;;\r
protected float deltaRotation;\r
- protected float duration;\r
- protected float invDuration;\r
- protected float taken = 0;\r
- protected Actor target;\r
- protected boolean done;\r
\r
public static RotateTo $ (float rotation, float duration) {\r
RotateTo action = pool.obtain();\r
}\r
\r
@Override public void act (float delta) {\r
- taken += delta;\r
- if (taken >= duration) {\r
- taken = duration;\r
+ float alpha = createInterpolatedAlpha(delta);\r
+ if (done) {\r
target.rotation = rotation;\r
- done = true;\r
- return;\r
+ } else {\r
+ target.rotation = startRotation + deltaRotation * alpha;\r
}\r
-\r
- float alpha = taken * invDuration;\r
- target.rotation = startRotation + deltaRotation * alpha;\r
- }\r
-\r
- @Override public boolean isDone () {\r
- return done;\r
}\r
\r
@Override public void finish () {\r
+ super.finish();\r
pool.free(this);\r
- if(listener != null)\r
- listener.completed(this);\r
}\r
\r
@Override public Action copy () {\r
/*\r
- * Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)\r
+ * Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com), Moritz Post\r
+ * (moritzpost@gmail.com)\r
* \r
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the\r
* License. You may obtain a copy of the License at\r
\r
import com.badlogic.gdx.scenes.scene2d.Action;\r
import com.badlogic.gdx.scenes.scene2d.Actor;\r
+import com.badlogic.gdx.scenes.scene2d.AnimationAction;\r
import com.badlogic.gdx.utils.Pool;\r
\r
-public class ScaleTo extends Action {\r
- static final Pool<ScaleTo> pool = new Pool<ScaleTo>(4, 100) {\r
- protected ScaleTo newObject () {\r
+public class ScaleTo extends AnimationAction {\r
+\r
+ private static final Pool<ScaleTo> pool = new Pool<ScaleTo>(4, 100) {\r
+ @Override protected ScaleTo newObject () {\r
return new ScaleTo();\r
}\r
};\r
protected float startScaleY;\r
protected float deltaScaleX;\r
protected float deltaScaleY;\r
- protected float duration;\r
- protected float invDuration;\r
- protected float taken = 0;\r
- protected Actor target;\r
- protected boolean done;\r
\r
- public static ScaleTo $ (float scaleX, float scaleY, float duration) {\r
+ public static AnimationAction $ (float scaleX, float scaleY, float duration) {\r
ScaleTo action = pool.obtain();\r
action.scaleX = scaleX;\r
action.scaleY = scaleY;\r
}\r
\r
@Override public void act (float delta) {\r
- taken += delta;\r
- if (taken >= duration) {\r
- taken = duration;\r
+ float alpha = createInterpolatedAlpha(delta);\r
+ if (done) {\r
target.scaleX = scaleX;\r
target.scaleY = scaleY;\r
- done = true;\r
- return;\r
+ } else {\r
+ target.scaleX = startScaleX + deltaScaleX * alpha;\r
+ target.scaleY = startScaleY + deltaScaleY * alpha;\r
}\r
-\r
- float alpha = taken * invDuration;\r
- target.scaleX = startScaleX + deltaScaleX * alpha;\r
- target.scaleY = startScaleY + deltaScaleY * alpha;\r
- }\r
-\r
- @Override public boolean isDone () {\r
- return done;\r
}\r
\r
@Override public void finish () {\r
+ super.finish();\r
pool.free(this);\r
- if(listener != null)\r
- listener.completed(this);\r
}\r
\r
@Override public Action copy () {\r
--- /dev/null
+/*\r
+ * Copyright 2011 Moritz Post (moritzpost@gmail.com)\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the\r
+ * License. You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"\r
+ * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+\r
+package com.badlogic.gdx.scenes.scene2d.interpolators;\r
+\r
+import com.badlogic.gdx.scenes.scene2d.Interpolator;\r
+import com.badlogic.gdx.utils.Pool;\r
+\r
+/**\r
+ * An interpolator where the rate of change starts out slowly and then accelerates over time.\r
+ * \r
+ * @author Moritz Post <moritzpost@gmail.com>\r
+ */\r
+public class AccelerateInterpolator implements Interpolator {\r
+\r
+ private static final float DEFAULT_FACTOR = 1.0f;\r
+\r
+ private static final Pool<AccelerateInterpolator> pool = new Pool<AccelerateInterpolator>(4, 100) {\r
+ @Override protected AccelerateInterpolator newObject () {\r
+ return new AccelerateInterpolator();\r
+ }\r
+ };\r
+\r
+ private float factor;\r
+\r
+ private double doubledFactor;\r
+\r
+ AccelerateInterpolator () {\r
+ // hide constructor\r
+ }\r
+\r
+ /**\r
+ * Gets a new {@link AccelerateInterpolator} from a maintained pool of {@link Interpolator}s.\r
+ * \r
+ * @param factor the factor controlling the rate of change\r
+ * @return the obtained {@link AccelerateInterpolator}\r
+ */\r
+ public static AccelerateInterpolator $ (float factor) {\r
+ AccelerateInterpolator inter = pool.obtain();\r
+ inter.factor = factor;\r
+ inter.doubledFactor = factor * 2;\r
+ return inter;\r
+ }\r
+\r
+ /**\r
+ * Gets a new {@link AccelerateInterpolator} from a maintained pool of {@link Interpolator}s.\r
+ * <p>\r
+ * The initial factor is set to <code>{@value AccelerateInterpolator#DEFAULT_FACTOR}</code>.\r
+ * \r
+ * @return the obtained {@link AccelerateInterpolator}\r
+ */\r
+ public static AccelerateInterpolator $ () {\r
+ return $(DEFAULT_FACTOR);\r
+ }\r
+\r
+ @Override public void finished () {\r
+ pool.free(this);\r
+ }\r
+\r
+ public float getInterpolation (float input) {\r
+ if (factor == 1.0f) {\r
+ return input * input;\r
+ } else {\r
+ return (float)Math.pow(input, doubledFactor);\r
+ }\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright 2011 Moritz Post (moritzpost@gmail.com)\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the\r
+ * License. You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"\r
+ * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+\r
+package com.badlogic.gdx.scenes.scene2d.interpolators;\r
+\r
+import com.badlogic.gdx.scenes.scene2d.Interpolator;\r
+import com.badlogic.gdx.utils.Pool;\r
+\r
+/**\r
+ * An {@link Interpolator} where the changes start backwards and than spring forward as the time progresses.\r
+ * \r
+ * @author Moritz Post <moritzpost@gmail.com>\r
+ */\r
+public class AnticipateInterpolator implements Interpolator {\r
+\r
+ private static final float DEFAULT_TENSION = 2.0f;\r
+\r
+ private static final Pool<AnticipateInterpolator> pool = new Pool<AnticipateInterpolator>(4, 100) {\r
+ @Override protected AnticipateInterpolator newObject () {\r
+ return new AnticipateInterpolator();\r
+ }\r
+ };\r
+\r
+ private float tension;\r
+\r
+ AnticipateInterpolator () {\r
+ // hide from the world\r
+ }\r
+\r
+ /**\r
+ * Gets a new {@link AnticipateInterpolator} from a maintained pool of {@link Interpolator}s.\r
+ * \r
+ * @param tension the tension controlling the rate spring effect of the animation\r
+ * @return the obtained {@link AccelerateInterpolator}\r
+ */\r
+ public static AnticipateInterpolator $ (float tension) {\r
+ AnticipateInterpolator inter = pool.obtain();\r
+ inter.tension = tension;\r
+ return inter;\r
+ }\r
+\r
+ /**\r
+ * Gets a new {@link AnticipateInterpolator} from a maintained pool of {@link Interpolator}s.\r
+ * <p>\r
+ * The initial tension is set to <code>{@value AnticipateInterpolator#DEFAULT_TENSION}</code>.\r
+ * \r
+ * @return the obtained {@link AnticipateInterpolator}\r
+ */\r
+ public static AnticipateInterpolator $ () {\r
+ return $(DEFAULT_TENSION);\r
+ }\r
+\r
+ @Override public void finished () {\r
+ pool.free(this);\r
+ }\r
+\r
+ public float getInterpolation (float t) {\r
+ return t * t * ((tension + 1) * t - tension);\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright 2011 Moritz Post (moritzpost@gmail.com)\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the\r
+ * License. You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"\r
+ * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+\r
+package com.badlogic.gdx.scenes.scene2d.interpolators;\r
+\r
+import com.badlogic.gdx.scenes.scene2d.Interpolator;\r
+import com.badlogic.gdx.utils.Pool;\r
+\r
+/**\r
+ * An interpolator where the rate of change starts out fast and then decelerates over time.\r
+ * \r
+ * @author Moritz Post <moritzpost@gmail.com>\r
+ */\r
+public class DecelerateInterpolator implements Interpolator {\r
+\r
+ private static final float DEFAULT_FACTOR = 1.0f;\r
+\r
+ private static final Pool<DecelerateInterpolator> pool = new Pool<DecelerateInterpolator>(4, 100) {\r
+ @Override protected DecelerateInterpolator newObject () {\r
+ return new DecelerateInterpolator();\r
+ }\r
+ };\r
+\r
+ private float factor;\r
+\r
+ private double doubledFactor;\r
+\r
+ DecelerateInterpolator () {\r
+ // hide constructor\r
+ }\r
+\r
+ /**\r
+ * Gets a new {@link DecelerateInterpolator} from a maintained pool of {@link Interpolator}s.\r
+ * \r
+ * @param factor the factor controlling the rate of change\r
+ * @return the obtained {@link DecelerateInterpolator}\r
+ */\r
+ public static DecelerateInterpolator $ (float factor) {\r
+ DecelerateInterpolator inter = pool.obtain();\r
+ inter.factor = factor;\r
+ inter.doubledFactor = factor * 2;\r
+ return inter;\r
+ }\r
+\r
+ /**\r
+ * Gets a new {@link DecelerateInterpolator} from a maintained pool of {@link Interpolator}s.\r
+ * <p>\r
+ * The initial factor is set to <code>{@value DecelerateInterpolator#DEFAULT_FACTOR}</code>.\r
+ * \r
+ * @return the obtained {@link DecelerateInterpolator}\r
+ */\r
+ public static DecelerateInterpolator $ () {\r
+ return $(DEFAULT_FACTOR);\r
+ }\r
+\r
+ @Override public void finished () {\r
+ pool.free(this);\r
+ }\r
+\r
+ public float getInterpolation (float input) {\r
+ if (factor == 1.0f) {\r
+ return 1.0f - (1.0f - input) * (1.0f - input);\r
+ } else {\r
+ return (float)(1.0f - Math.pow((1.0f - input), doubledFactor));\r
+ }\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright 2011 Moritz Post (moritzpost@gmail.com)\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the\r
+ * License. You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"\r
+ * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+\r
+package com.badlogic.gdx.scenes.scene2d.interpolators;\r
+\r
+import com.badlogic.gdx.scenes.scene2d.Interpolator;\r
+import com.badlogic.gdx.utils.Pool;\r
+\r
+/**\r
+ * A very simple {@link Interpolator} which provides a linear progression by just returning the current input.\r
+ * \r
+ * @author Moritz Post <moritzpost@gmail.com>\r
+ */\r
+public class LinearInterpolator implements Interpolator {\r
+\r
+ private static final Pool<LinearInterpolator> pool = new Pool<LinearInterpolator>(4, 100) {\r
+ @Override protected LinearInterpolator newObject () {\r
+ return new LinearInterpolator();\r
+ }\r
+ };\r
+\r
+ LinearInterpolator () {\r
+ // hide constructor\r
+ }\r
+\r
+ /**\r
+ * Gets a new {@link LinearInterpolator} from a maintained pool of {@link Interpolator}s.\r
+ * \r
+ * @return the obtained {@link LinearInterpolator}\r
+ */\r
+ public static LinearInterpolator $ () {\r
+ return pool.obtain();\r
+ }\r
+\r
+ @Override public void finished () {\r
+ pool.free(this);\r
+ }\r
+\r
+ @Override public float getInterpolation (float input) {\r
+ return input;\r
+ }\r
+\r
+}\r