标签:
不知道线性插值的,自行百度。
核心代码:
// 缩放平滑因子
private float zoomSmothFactor = 5f;
// 滑动
private float moveSmothFactor = 12f;
Vector2 oldZoomVector = new Vector2(0, 1);
Vector2 newZoomVector = new Vector2(0, 1f);
Vector2 oldPositionVector = new Vector2();
Vector2 newPositionVector = new Vector2();
public void check(){
// 使用线性内插,起到平顺过度的效果
oldZoomVector.lerp(newZoomVector, zoomSmothFactor * Math.min(0.05f, deltaTime));
if (newPositionVector.x != 0 || newPositionVector.y != 0) {
oldPositionVector.lerp(newPositionVector, moveSmothFactor * Math.min(0.06f, deltaTime));
}
camera.position.x = oldPositionVector.x;
camera.position.y = oldPositionVector.y;
camera.zoom = oldZoomVector.y;
}
@Override
public boolean zoom(float initialDistance, float distance) {
//与pinch对应,也是是一个多点触摸的手势,并且两个手指做出放大的动作
float zoomFactor = initialDistance / distance;
newZoomVector.y = zoomFactor;
return false;
}
在每次绘制前或后,调用check()方法即可。上面的影响因子,可自行调节,以达到最优效果。
标签:
原文地址:http://my.oschina.net/oahcfly/blog/363476