[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 iainh » Fri May 25, 2012 3:02 pm

Thanks for the clear explanation! It is really helpful and saves me hours of time. :D

I may continue work on the game now.
iainh
 
Posts: 10
Joined: Mon May 14, 2012 8:15 pm

Re: [lib] Universal Tween Engine

Postby xeoshow » Tue May 14, 2013 12:24 am

Hi,

Can I use the Universal Tween Engine to do the page turning effect between 2 screens in libgdx? If yes, how? I can manage to use it to do the fadeout effect, but just not sure how to do the page turning (curl) effect...

Any help is appriaciated! Thanks.
xeoshow
 
Posts: 269
Joined: Mon Mar 18, 2013 1:12 am

Re: [lib] Universal Tween Engine

Postby ondesic » Tue May 21, 2013 8:50 pm

This engine looks great. I have searched though the wikidocs and looked at Get Started page. It seems like there are multiple ways to impliment the engine. Enough so that I am confused. I want to tween my jSprite class. My setup has the main class

Code: Select all
public class MyClass implements ApplicationListener{   
   @Override
   public void create() {      
   }

   @Override
   public void dispose() {
   }

   @Override
   public void render() {      
   }

   @Override
   public void resize(int width, int height) {
   }

   @Override
   public void pause() {
   }

   @Override
   public void resume() {
   }
}



I then have my own sprite class called jSprite:

Code: Select all
public class jSprite implements Comparable<jSprite>{
     public float x, y, width, height, scalex, scaley; ....
}


Of course this is the skeleton. Do I use TweenAccessor, Tweenable? I don't know. Others probably can, but I can't tell from the example where things are being placed. Could someone help me know where to put each part of the tween engine in my skeleton above?

Thanks so much!
ondesic
 
Posts: 33
Joined: Mon May 13, 2013 3:08 pm

Re: [lib] Universal Tween Engine

Postby semperhilaris » Wed May 29, 2013 6:36 pm

Hi onedesic,
use TweenAccessor. :)
Should look something like
Code: Select all
public class jSpriteAccessor implements TweenAccessor<jSprite> {
    public static final int TWEEN_X = 1;
   
    @Override
    public int getValues(jSprite target, int tweenType, float[] returnValues) {
        switch (tweenType) {
            case TWEEN_X: returnValues[0] = target.x; return 1;
            default: assert false; return -1;
        }
    }
   
    @Override
    public void setValues(jSprite target, int tweenType, float[] newValues) {
        switch (tweenType) {
            case TWEEN_X: target.x = newValues[0]; break;
            default: assert false; break;
        }
    }

}

That should make your x field tweenable. You can add more tween types for y, width, height, etc
Hope this helps!

regards
semperhilaris
 
Posts: 8
Joined: Sun Apr 28, 2013 12:36 pm

Re: [lib] Universal Tween Engine

Postby ondesic » Sat Jun 01, 2013 6:37 pm

Thanks so much!
ondesic
 
Posts: 33
Joined: Mon May 13, 2013 3:08 pm

Re: [lib] Universal Tween Engine

Postby mmachida » Tue Feb 03, 2015 5:06 pm

Obli wrote:Hello,

Did you read the "Get Started" page ? Everything is up to date there, and explained in details.

Don't hesitate to tell me what is the issue, and to post some code samples.

Hello, can you help me? I'm following the "getStarted" tutorial and I got this error:
Code: Select all
Exception in thread "LWJGL Application" java.lang.RuntimeException: No TweenAccessor was found for the target


My code below.

ParticleClass:
Code: Select all
public class ParticleClass
{
    private float x, y;
    public float getX()
    {
        return x;
    }
    public float getY()
    {
        return y;
    }
    public void setX(float x)
    {
        this.x = x;
    }
    public void setY(float y)
    {
        this.y = y;
    }
}


ParticleAccessor:
Code: Select all
public class ParticleAccessor implements TweenAccessor<ParticleClass>
{
   // The following lines define the different possible tween types.
    // It's up to you to define what you need :-)

    public static final int POSITION_X = 1;
    public static final int POSITION_Y = 2;
    public static final int POSITION_XY = 3;

    // TweenAccessor implementation

    @Override
    public int getValues(ParticleClass 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();
                return 2;
            default: assert false; return -1;
        }   
    }
   
    @Override
    public void setValues(ParticleClass 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]);
                break;
            default: assert false; break;
        }
    }
}


Create method in my class:
Code: Select all
      Tween.registerAccessor(ParticleClass.class, new ParticleAccessor());
      tweenManager = new TweenManager();
      
      sprite = new Sprite(new Texture("images/bullet_test.png"));
      sprite.setPosition(200, 200);
      
      Tween.to(sprite, ParticleAccessor.POSITION_XY, 1.0f)
      .target(50, 50)
      .start(tweenManager);


Render method in my class:
Code: Select all
      Gdx.gl.glClearColor(255, 255, 255, 1);
      Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);

      //Batch
      batch.setProjectionMatrix(camera.combined);
         camera.position.set(viewport.getWorldWidth()/2, viewport.getWorldHeight()/2, 0);
      camera.update();
      batch.begin();
         sprite.draw(batch);
      batch.end();
      tweenManager.update(delta);


--EDITED

Now I understand, the "object" must be same type of the class of ParticleAcessor acess.
mmachida
 
Posts: 65
Joined: Tue Mar 25, 2014 8:26 pm

Previous

Return to Libgdx Contributions

Who is online

Users browsing this forum: No registered users and 1 guest