此代码将在 cont2 中生成图像,这是一个 ViewContainer,首先从 (0,100) 移动到 (100, 100)。
Timeline.createSequence()
.push(Tween.set(cont2, ViewContainerAccessor.POSITION_XY))
.push(Tween.to(cont2, ViewContainerAccessor.POSITION_XY, 0.5f).target(0,100))
.push(Tween.to(cont2, ViewContainerAccessor.POSITION_XY, 0.5f).target(100,100))
.start(tweenManager);
在我的代码中,图像首先向下,然后向右。
也许在您的代码中应该是这样的
Timeline.createSequence()
.push(Tween.to(sprTurtle, SpriteAccessor.POS_XY, 0.4f)
.waypoint(posTurtle[0] + (20 * density), posTurtle[1] + (20 * density))
.target(posTurtle[0] + (30 * density), posTurtle[1])
.ease(Quad.INOUT)
.path(TweenPaths.catmullRom)
.repeatYoyo(Tween.INFINITY, 0)
.delay(0.1f))
.push(Tween.to(sprTurtle, SpriteAccessor.POS_XY, 1f)
.target(50, 50)
.repeat(Tween.INFINITY, 0))
.start(tweenManager);
如果您确实希望两个图像同时移动,则必须制作两个 ViewContainer 以便它们可以同时移动。
在官方演示 apkMainActivity.java
中,您可以看到以下代码。我添加and来同时移动两个图像。LinearLayout genueHamster2
VieewContainer cont2
private LinearLayout genueHamster;
private LinearLayout genueHamster2; // I add another LinearLayout so we could have
// two images at the same time.
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Setup it
// a linearlayout in activity_main.xml
genueHamster = (LinearLayout) findViewById(R.id.main_cont);
// add for second image
genueHamster2 = (LinearLayout) findViewById(R.id.main_cont_2);
setTweenEngine();
}
public void startAnimation(View v) {
// Create object which we will animate
ViewContainer cont = new ViewContainer();
// Add a new container for the second image.
ViewContainer cont2 = new ViewContainer();
// pass our real container
cont.view = genueHamster;
// put it into the second container
cont2.view = genueHamster2;
// /start animations
// Now you can have two images moving at the same time.
Tween.to(cont, ViewContainerAccessor.POSITION_XY, 0.5f)
.target(500, 0).ease(Bounce.OUT).delay(1.0f)
.start(tweenManager);
Tween.to(cont2, ViewContainerAccessor.POSITION_XY, 0.5f)
.target(0, 500)
.ease(Bounce.OUT)
.delay(1.0f)
.repeatYoyo(2, 0.5f)
.start(tweenManager);
}