我用TweetEngine(X和Y位置)一次插值两个值,但只更新了X ...
访问者类:
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);
输出(设置器中设置的日志)是这样的(修剪以提高可读性):
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
如您所见,第一个值是插值的,但第二个值不是,直到最后一次访问,才将其设置为目标值。
答案 0 :(得分:2)
您的import java.text.SimpleDateFormat;
import java.util.Date;
public class DateDifferentExample {
public static void main(String[] args) {
String dateStart = "01/14/2012 09:29:58";
String dateStop = "01/15/2012 10:31:48";
//HH converts hour in 24 hours format (0-23), day calculation
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
Date d1 = null;
Date d2 = null;
try {
d1 = format.parse(dateStart);
d2 = format.parse(dateStop);
//in milliseconds
long diff = d2.getTime() - d1.getTime();
long diffSeconds = diff / 1000 % 60;
long diffMinutes = diff / (60 * 1000) % 60;
long diffHours = diff / (60 * 60 * 1000) % 24;
long diffDays = diff / (24 * 60 * 60 * 1000);
System.out.print(diffDays + " days, ");
System.out.print(diffHours + " hours, ");
System.out.print(diffMinutes + " minutes, ");
System.out.print(diffSeconds + " seconds.");
} catch (Exception e) {
e.printStackTrace();
}
}
方法需要返回2而不是1,因为您有两个要修改的值。