Lud*_*vik 73
由于LibGDX的变化,这个答案已经过时了.有关最新文档,请参阅scene2d wiki页面.
LibGDX中有各种可用的操作可供您使用.他们是com.badlogic.gdx.scenes.scene2d.actions
包装.我会说有3种动作:
动画操作会修改actor的各种属性,例如位置,旋转,缩放和alpha.他们是:
复合操作在一个操作中组合多个操作,有:
其他行为:
每个操作都有一个静态方法$
,用于创建该Action的实例.创建动画动作的示例:
MoveTo move = MoveTo.$(200, 200, 0.5f); //move Actor to location (200,200) in 0.5 s
RotateTo rotate = RotateTo.$(60, 0.5f); //rotate Actor to angle 60 in 0.5 s
Run Code Online (Sandbox Code Playgroud)
创建更复杂的动作序列的示例:
Sequence sequence = Sequence.$(
MoveTo.$(200, 200, 0.5f), //move actor to 200,200
RotateTo.$(90, 0.5f), //rotate actor to 90°
FadeOut.$(0.5f), //fade out actor (change alpha to 0)
Remove.$() //remove actor from stage
);
Run Code Online (Sandbox Code Playgroud)
动画动作也让你指定Interpolator
.有各种实现:
插值器Javadoc:插值器定义动画的变化率.这允许基本动画效果(alpha,缩放,平移,旋转)加速,减速等.要将插补器设置为您的动作:
action.setInterpolator(AccelerateDecelerateInterpolator.$());
Run Code Online (Sandbox Code Playgroud)
当你准备好内插器的动作时,你就可以将动作设置为你的演员了:
actor.action(yourAction);
Run Code Online (Sandbox Code Playgroud)
要实际执行为舞台上的actor定义的所有动作,您必须在render方法中调用stage.act(...):
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
Run Code Online (Sandbox Code Playgroud)
she*_*tan 12
您应该尝试使用Universal Tween Engine.它易于使用且功能强大......它使得阅读复杂的动画在公园散步,因为所有命令都可以链接.见下面的例子.
脚步:
1.从此处下载库
2.创建一个访问者类.你可以节省时间,从这里抓住我正在使用的那个.
3.在您的Game类中声明TweenManager
public static TweenManager tweenManager;
Run Code Online (Sandbox Code Playgroud)
在create方法中:
tweenManager = new TweenManager();
Run Code Online (Sandbox Code Playgroud)
在渲染方法中:
tweenManager.update(Gdx.graphics.getDeltaTime());
Run Code Online (Sandbox Code Playgroud)
4.随意使用它.防爆.
使用弹性插值在1.5秒内将actor移动到位置(100,200):
Tween.to(actor, ActorAccesor.POSITION_XY, 1.5f)
.target(100, 200)
.ease(Elastic.INOUT)
.start(tweenManager);
Run Code Online (Sandbox Code Playgroud)
创建复杂的动画序列:
Timeline.createSequence()
// First, set all objects to their initial positions
.push(Tween.set(...))
.push(Tween.set(...))
.push(Tween.set(...))
// Wait 1s
.pushPause(1.0f)
// Move the objects around, one after the other
.push(Tween.to(...))
.push(Tween.to(...))
.push(Tween.to(...))
// Then, move the objects around at the same time
.beginParallel()
.push(Tween.to(...))
.push(Tween.to(...))
.push(Tween.to(...))
.end()
// And repeat the whole sequence 2 times
.repeatYoyo(2, 0.5f)
// Let's go!
.start(tweenManager);
Run Code Online (Sandbox Code Playgroud)
更多细节在这里
更新:替换死链接
Dro*_*sta 11
这是使用类com.badlogic.gdx.math.Interpolation的有用链接.因此,例如,要创建具有效果的moveTo ation,您可以简单地使用:
myActor.addAction(Actions.moveTo(100, 200, 0.7f, Interpolation.bounceOut));
Run Code Online (Sandbox Code Playgroud)
如果将Actions类导入为static(必须手动设置):
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
Run Code Online (Sandbox Code Playgroud)
那么,你可以像这样使用你的行动:
myActor.addAction(moveTo(100, 200, 0.7f, Interpolation.bounceOut));
Run Code Online (Sandbox Code Playgroud)