简体   繁体   中英

How to finish or end a tween instantly with Universal Tween Engine?

Universal Tween Engine has a TweenManager.killTarget() option, but this kills a tween without finishing it.

I want to end a tween having the target set to the end of the tween instantly. Unfortunatly I can't find a way to do it? The same goes for Timelines.

Anyone knows how to do this?

You can explicitly call update() on a Tween or a Timeline with a delta of the duration of your animation (personally I'd use a Timeline).

For example (assuming you have a libgdx Sprite called spr and a SpriteAccessor that correctly implements the relevant tween types):

// scale and move a sprite over 2 seconds
Timeline tl = Timeline.createSequence().
    .push(Tween.set(spr, SpriteAccessor.SCALE).target(1, 1))
    .push(Tween.set(spr, SpriteAccessor.POSITION).target(0, 0))
    .beginParallel()
        .push(Tween.to(spr, SpriteAccessor.SCALE, 2).target(2, 2))
        .push(Tween.to(spr, SpriteAccessor.POSITION, 2).target(50, 50))
    .end()
    .start(tweenManager);

// force the animation to complete
tl.update(2);
// no need to call kill() as isFinished gets set implicitly by the update

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM