所以我有这个精灵叫做播放器。我想将播放器从(30,30)移动到(40,40)。我四处寻找如何使用补间引擎做到这一点,而我得到的是使用它
Tween.to(player, Type.POSITION_XY, 1.0f)
但是,当我使用Type.POSITION_XY
的是
POSITION_XY cannot be resolved or is not a field
如果 POSITION_XY 不存在,我现在不知道该怎么做
使用这个类来补间精灵的位置。
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;
}
}
}
您需要将以下链接提供的 spriteaccessor 类放在 http://code.google.com/p/libgdx-texturepacker-gui/source/browse/src/aurelienribon/accessors/SpriteAccessor.java?r=c47de51d163f6facc57921495e70f9b1154b3426
并将 type.position_xy 更改为 spriteaccessor.pos_xy
此外,您需要在使用它之前注册此访问器..