[lib] Universal Tween Engine

Any community contributions to libgdx go here! Some may get included in the core API when permission is granted.

Re: [lib] Universal Tween Engine

Postby Aare » Wed Mar 07, 2012 7:14 pm

Actually, I didn`t dig much into the new version... the informations about the name and class changes sounded like a lot of work while not giving much profit. I already have half-finished project with a lot of tweens, and changing them would require time, while after fixing that bug I`m completly happy with what version 5.2 offers. Gr8 work on that library btw., if I would ever start another project I will definitely use the newest version of Tween Engine :)
Aare
 
Posts: 69
Joined: Mon Sep 05, 2011 10:02 pm

Re: [lib] Universal Tween Engine

Postby Obli » Thu Mar 08, 2012 3:37 pm

Nice spirit, I'm totally following the "while it works, don't change it" way of doing :)
Indeed, if you're project is near completion, you really don't need to upgrade!
Obli
 
Posts: 616
Joined: Mon Jan 10, 2011 6:18 pm
Location: Bordeaux, France

Re: [lib] Universal Tween Engine

Postby cuellarjmcg » Tue Mar 20, 2012 4:14 pm

Hi :D

I have a little question: How can I get the number of active Tweens? (I'm using newest version, 6.2).

In 6.1, I used the size() method in my TweenManager instance (but it doesn't exist anymore in 6.2). I see that theres is a Tween.getPoolSize(), but that gives me the size of the pool, not the active Tweens (as they end or get killed at some point). I mostly ask this for debugging purposes.

Is it possible?

Thanks in advance :D
cuellarjmcg
 
Posts: 230
Joined: Tue Feb 21, 2012 8:57 pm

Re: [lib] Universal Tween Engine

Postby Obli » Wed Mar 21, 2012 10:32 am

Hello!

I added size(), getRunningTweensCount(), getRunningTimelinesCount() and getObjects() to TweenManager. Pull from the trunk to update to latest version (a ant build script is provided).
Note that size() now only returns the number of managed objects, not including tweens and timelines nested inside top-level timelines. Instead, use getRunningTweensCount() and getRunningTimelinesCount() to have access to nested objects count.
Obli
 
Posts: 616
Joined: Mon Jan 10, 2011 6:18 pm
Location: Bordeaux, France

Re: [lib] Universal Tween Engine

Postby cuellarjmcg » Wed Mar 21, 2012 3:54 pm

Thank you very much :D
cuellarjmcg
 
Posts: 230
Joined: Tue Feb 21, 2012 8:57 pm

Re: [lib] Universal Tween Engine

Postby Saurav » Wed Mar 21, 2012 9:50 pm

I should probably update to the latest version as well. I think I'm running into a bug in Tween.kill(), or I'm not doing something right. I just noticed this last night, so haven't had much time to look into it. But the visual effect is that if I kill a flying enemy, sometimes it floats in space, spinning round and round, instead of falling to the ground. It looks quite cute :)
Saurav
 
Posts: 623
Joined: Sun Feb 27, 2011 7:59 pm

Re: [lib] Universal Tween Engine

Postby iainh » Fri May 25, 2012 10:02 am

Hi, thanks for the great tweening library! It is so helpful for game development.

I am trying to change the opacity of some particles in my code but with no success. And here is my fragment of code to change the opacity in ParticleAccessor

Code: Select all
@Override
public int getValues(ZombieParticle target, int tweenType, float[] returnValues) {
    switch (tweenType) {
           case POSITION_X: returnValues[0] = target.getX(); return 1;
           case POSITION_Y: returnValues[0] = target.getY(); return 1;
           case POSITION_XY:
               returnValues[0] = target.getX();
               returnValues[1] = target.getY();
               returnValues[2] = target.getColor().a;
               return 2;
           default: assert false; return -1;
        }
}

@Override
public void setValues(ZombieParticle target, int tweenType, float[] newValues) {
        switch (tweenType) {
           case POSITION_X: target.setX(newValues[0]); break;
           case POSITION_Y: target.setY(newValues[0]); break;
           case POSITION_XY:
               target.setX(newValues[0]);
               target.setY(newValues[1]);
              
               Color c = target.getColor();
            c.set(c.r, c.g, c.b, newValues[2]);
            target.setColor(c);
               break;
           default: assert false; break;
        }
}


And start tween with:
Code: Select all
Tween.to(dust1, ZombieParticleAccessor.POSITION_XY, 0.5f)
        .targetRelative(MathUtils.random(0.5f, 1.5f), MathUtils.random(0.1f, 1.2f), 0)
        .ease(Circ.OUT)
        .start(tweenManager);

Sorry if this is not related with this tween engine. :P
iainh
 
Posts: 10
Joined: Mon May 14, 2012 8:15 pm

Re: [lib] Universal Tween Engine

Postby Obli » Fri May 25, 2012 11:45 am

Change "return 2" into "return 3" in your "getValues() ... case POSITION_XY" code snippet, else the engine will only compute new values for the first 2 floats that are in the returnValues array ;)

Also, keep in mind that "targetRelative" call adds the given values to the current ones. Therefore, you're adding 0 to the current opacity. That won't change anything. Use -1 as the relative target for the opacity if you really want to use targetRelative :)
Obli
 
Posts: 616
Joined: Mon Jan 10, 2011 6:18 pm
Location: Bordeaux, France

Re: [lib] Universal Tween Engine

Postby iainh » Fri May 25, 2012 1:45 pm

Haha, you are right about the "targetRelative" thingy. Thanks for the tips!! Silly me :mrgreen: It is working fine now! Thank you very much :lol:

Btw, I have another question about how to dispose the objects used in the Tweens. Do I need to free them all once I have done tweening with them?

I have a ArrayList that stores all the particles
Code: Select all
 List<ZombieParticle> zombieParticles = new ArrayList<ZombieParticle>();


And I want to remove the object inside the list once the object's tweening is completed. Here is the code that I am using now
Code: Select all
Tween.to(dust1, ZombieParticleAccessor.POSITION_XY, 1f)
         .setCallback(new TweenCallback() {
            @Override public void onEvent(int type, BaseTween<?> source) {
                  // remove target in the list once tween is completed
                 zombieParticles.remove((ZombieParticle) source.getUserData());
             }
    })
    .targetRelative(MathUtils.random(1f, 2f), MathUtils.random(0.1f, 1.5f), -0.5f)
    .ease(Circ.OUT)
    .start(tweenManager);


souce.getUserData() always return null in my case. I wonder is there anything I am doing wrong here?

Sorry if my question sounds too novice to you as I am new to this great tween engine and Android development. :oops:

Thanks for helping.
iainh
 
Posts: 10
Joined: Mon May 14, 2012 8:15 pm

Re: [lib] Universal Tween Engine

Postby Obli » Fri May 25, 2012 2:21 pm

As long as you use a TweenManager, you don't have to worry about disposing anything since the manager will take care for it for you.

In your callback, you want to get back the target of the tween. Use:
Code: Select all
ZombieParticle target = ((Tween) source).getTarget();


The getUserData() method lets you get a custom object you can attach to any tween or timeline with setUserData(). It's often used to pass arguments to the callback. If you did not call setUserData, then getUserData returns null :)
Obli
 
Posts: 616
Joined: Mon Jan 10, 2011 6:18 pm
Location: Bordeaux, France

PreviousNext

Return to Libgdx Contributions

Who is online

Users browsing this forum: No registered users and 3 guests