您可以使用GestureDetector来处理平移输入。方法gestureListener.pan
可以更新动画位置参数。
private int screenPixelsToAnimationPositionRatio = 0.01f; //will need to tweak this and probably adjust it at runtime based on screen dimensions and resolution
private float animationPosition = 0; //from 0 to 1, fraction of animation complete
public void create() {
//...
GestureAdapter gestureAdapter = new GestureAdapter {
@Override
public boolean pan (float x, float y, float deltaX, float deltaY) {
animationPosition += deltaX * screenPixelsToAnimationPositionRatio;
animationPosition = MathUtils.clamp(animationPosition, 0, 1);
return true;
}
};
GestureDetector gestureDetector = new GestureDetector(gestureAdapter);
Gdx.input.setInputProcessor(gestureDetector); //or put the detector in an InputMultiplexer with your other input listeners.
}
那么你会创建一个可更新的基础上animationPosition
当前值的对象的位置和旋转的方法。你需要找出决定你想要的运动的方程。例如,一些看起来有点像你上面说明什么:
private void updateAnimation(){
x = animationPosition * 30;
float y = 0, rotation = 0;
if (animationPosition >= 0.25f) {
float jumpPosition = Math.min(1, (animationPosition - 0.25f)/0.5f);
y = 30 * (1 - Interpolation.pow2In.apply(Math.abs(2 * jumpPosition - 1)));
rotation = 180 * jumpPosition;
}
mySprite.setPosition(x, y);
mySprite.setRotation(rotation);
}
然后在某处render
调用此更新方法。
有滚动视图。监视它滚动了多少。设置您的动画以框架动画。动画当前帧= Math.floor(scrollview.scrollX/scrollview.totalScrollX * animation.totalFrames) – Diniden
不错。问题在于我无法预先录制帧,因为用户需要自己创建它的“蓝色矩形” – brumbrum
您必须更详细地解释您的场景。即使用户正在制作他自己的内容,您也应该可以控制生成的帧。我不明白我的方法如何需要“预先计算”的价值。 – Diniden