Universal TweenEngine 一次有多个值
Universal TweenEngine several values at once
我正在使用 TweetEngine 一次插入两个值(X 和 Y 位置),但只有 X 被更新...
存取器class:
private static class PersonTweenAccessor implements TweenAccessor<Person> {
public static final int POSITION_XY = 1;
@Override
public int getValues(Person target, int tweenType, float[] returnValues) {
switch(tweenType) {
case POSITION_XY:
returnValues[0] = target.position.x;
returnValues[1] = target.position.y;
return 1;
default:
return -1;
}
}
@Override
public void setValues(Person target, int tweenType, float[] newValues) {
switch(tweenType) {
case POSITION_XY:
target.position.set(newValues[0], newValues[1]);
Gdx.app.log("position", newValues[0] + "," + newValues[1]);
break;
}
}
}
补间创作:
Gdx.app.log("Tween start", "From (" + position.x + "," + position.y + ") to (" + targetPoint.x + "," + targetPoint.y + ")");
Tween.to(this, PersonTweenAccessor.POSITION_XY, distance / speed)
.target(targetPoint.x, targetPoint.y)
.ease(TweenEquations.easeNone)
.setCallback(positionTweenCallback)
.start(GameWorld.tweenManager);
输出(在 setter 中设置的日志)是这样的(经过修剪以提高可读性):
Tween start: From (50.0,20.0) to (283,25)
position: 51.305202,20.0
position: 52.14488,20.0
position: 53.2509,20.0
...
position: 280.70465,20.0
position: 281.80902,20.0
position: 282.85034,20.0
position: 283.0,25.0
如您所见,第一个值被插值但第二个值没有被插值,直到最后一次访问,其中被设置为它的目标值。
您的 getValues
方法需要 return 2,而不是 1,因为您有两个要修改的值。
我正在使用 TweetEngine 一次插入两个值(X 和 Y 位置),但只有 X 被更新...
存取器class:
private static class PersonTweenAccessor implements TweenAccessor<Person> {
public static final int POSITION_XY = 1;
@Override
public int getValues(Person target, int tweenType, float[] returnValues) {
switch(tweenType) {
case POSITION_XY:
returnValues[0] = target.position.x;
returnValues[1] = target.position.y;
return 1;
default:
return -1;
}
}
@Override
public void setValues(Person target, int tweenType, float[] newValues) {
switch(tweenType) {
case POSITION_XY:
target.position.set(newValues[0], newValues[1]);
Gdx.app.log("position", newValues[0] + "," + newValues[1]);
break;
}
}
}
补间创作:
Gdx.app.log("Tween start", "From (" + position.x + "," + position.y + ") to (" + targetPoint.x + "," + targetPoint.y + ")");
Tween.to(this, PersonTweenAccessor.POSITION_XY, distance / speed)
.target(targetPoint.x, targetPoint.y)
.ease(TweenEquations.easeNone)
.setCallback(positionTweenCallback)
.start(GameWorld.tweenManager);
输出(在 setter 中设置的日志)是这样的(经过修剪以提高可读性):
Tween start: From (50.0,20.0) to (283,25)
position: 51.305202,20.0
position: 52.14488,20.0
position: 53.2509,20.0
...
position: 280.70465,20.0
position: 281.80902,20.0
position: 282.85034,20.0
position: 283.0,25.0
如您所见,第一个值被插值但第二个值没有被插值,直到最后一次访问,其中被设置为它的目标值。
您的 getValues
方法需要 return 2,而不是 1,因为您有两个要修改的值。