Question

So I have this sprite called player. I want to move the player from for example (30,30) to (40,40). I've looked around for a how to do this with tween engine and what iI got was to use this

Tween.to(player, Type.POSITION_XY, 1.0f)

However when I use Type.POSITION_XY is that

POSITION_XY cannot be resolved or is not a field 

I'm sortof lost as to how to do this now if POSITION_XY does not exist

Was it helpful?

Solution 2

You need to put spriteaccessor class provided at following link http://code.google.com/p/libgdx-texturepacker-gui/source/browse/src/aurelienribon/accessors/SpriteAccessor.java?r=c47de51d163f6facc57921495e70f9b1154b3426

And change type.position_xy to spriteaccessor.pos_xy

Also you need to register this accessor before using it..

OTHER TIPS

use this class for tweening the position of spirte.

public class SpriteAccessor implements TweenAccessor<Sprite> {

        public static final int POS_XY = 1;
        public static final int CPOS_XY = 2;
        public static final int SCALE_XY = 3;
        public static final int ROTATION = 4;
        public static final int OPACITY = 5;
        public static final int TINT = 6;

        @Override
        public int getValues(Sprite target, int tweenType, float[] returnValues) {
            switch (tweenType) {
                case POS_XY:
                    returnValues[0] = target.getX();
                    returnValues[1] = target.getY();
                    return 2;

                case CPOS_XY:
                    returnValues[0] = target.getX() + target.getWidth()/2;
                    returnValues[1] = target.getY() + target.getHeight()/2;
                    return 2;

                case SCALE_XY:
                    returnValues[0] = target.getScaleX();
                    returnValues[1] = target.getScaleY();
                    return 2;

                case ROTATION: returnValues[0] = target.getRotation(); return 1;
                case OPACITY: returnValues[0] = target.getColor().a; return 1;

                case TINT:
                    returnValues[0] = target.getColor().r;
                    returnValues[1] = target.getColor().g;
                    returnValues[2] = target.getColor().b;
                    return 3;

                default: assert false; return -1;
            }
        }

        @Override
        public void setValues(Sprite target, int tweenType, float[] newValues) {
            switch (tweenType) {
                case POS_XY: target.setPosition(newValues[0], newValues[1]); break;
                case CPOS_XY: target.setPosition(newValues[0] - target.getWidth()/2, newValues[1] - target.getHeight()/2); break;
                case SCALE_XY: target.setScale(newValues[0], newValues[1]); break;
                case ROTATION: target.setRotation(newValues[0]); break;

                case OPACITY:
                    Color c = target.getColor();
                    c.set(c.r, c.g, c.b, newValues[0]);
                    target.setColor(c);
                    break;

                case TINT:
                    c = target.getColor();
                    c.set(newValues[0], newValues[1], newValues[2], c.a);
                    target.setColor(c);
                    break;

                default: assert false;
            }
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top