java – libgdx中的通用补间引擎的补间补间?

前端之家收集整理的这篇文章主要介绍了java – libgdx中的通用补间引擎的补间补间?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我有一个sprite循环补间,就像一个空闲动画.我想为它添加另一个补间,所以它们同时播放. (例如,如果我的第一个补间移动它,我的第二个补间移动它,我希望它向上和向右移动.)

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

这是我的代码

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,1f)
    .target(50,50)
    .repeat(Tween.INFINITY,0)
    .start(tweenManager);  
最佳答案
代码将使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,0.5f).target(100,100))
        .start(tweenManager);

在我的代码中,图像首先下降,然后向右.

也许在你的代码中应该是这样的

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

如果您确实希望同时移动两个图像,则必须创建两个ViewContainer,以便它们可以同时移动.

official demo apk的MainActivity.java中,您可以看到以下代码.我添加了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,0.5f)
            .target(500,0).ease(Bounce.OUT).delay(1.0f)
            .start(tweenManager);               

    Tween.to(cont2,0.5f)
            .target(0,500)
            .ease(Bounce.OUT)
            .delay(1.0f)
            .repeatYoyo(2,0.5f)
            .start(tweenManager);

  }
原文链接:https://www.f2er.com/android/430819.html

猜你在找的Android相关文章