5

我有一个循环补间的精灵,就像一个空闲动画。我想给它添加另一个补间,这样它们就可以同时播放了。(例如,如果我的第一个补间将其向上移动,而我的第二个补间将其向右移动,我希望它向上和向右移动。)

但是每当我播放第二个补间时,它似乎完全覆盖了第一个补间。我究竟做错了什么?

这是我的代码:

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)
    .start(tweenManager);
Tween.to(sprTurtle, SpriteAccessor.POS_XY, 1f)
    .target(50, 50)
    .repeat(Tween.INFINITY, 0)
    .start(tweenManager);  
4

2 回答 2

5

此代码将在 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 genueHamster2VieewContainer 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);

  }
于 2013-03-14T13:50:11.083 回答
0

您正在寻找的是Timeline.createParallel方法。

于 2013-08-06T20:53:39.863 回答