Actions of Actors in libgdx

后端 未结 3 1583
隐瞒了意图╮
隐瞒了意图╮ 2020-12-12 22:45

I have made my Actor, but I am unclear on how to take advantage of the action and act methods. Outside of the basic Javadoc, I have not found a go

3条回答
  •  死守一世寂寞
    2020-12-12 23:38

    You should give Universal Tween Engine a try. It's easy to use and really powerful... and it makes reading complex animations a walk in the park because all commands can be chained. See examples bellow.

    Steps:

    1. Download the library from here
    2. Create an accesor class. You can save the time and grab the one I was using from here.
    3. In your Game class declare the TweenManager

        public static TweenManager tweenManager;
    


    In the create method:

        tweenManager = new TweenManager();
    


    In the render method:

        tweenManager.update(Gdx.graphics.getDeltaTime());
    


    4. Use it however you want. Ex.

    Move actor to position (100, 200) in 1.5 seconds with elastic interpolation:

    Tween.to(actor, ActorAccesor.POSITION_XY, 1.5f)
         .target(100, 200)
         .ease(Elastic.INOUT)
         .start(tweenManager);
    


    Create a complex sequence of animations:

    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);
    


    More details here

    UPDATE: replaced dead link

提交回复
热议问题