不知道線性插值的,自行百度。ide
核心代碼:spa
// 縮放平滑因子 it
private float zoomSmothFactor = 5f;io
// 滑動百度
private float moveSmothFactor = 12f;float
Vector2 oldZoomVector = new Vector2(0, 1);方法
Vector2 newZoomVector = new Vector2(0, 1f);im
Vector2 oldPositionVector = new Vector2();di
Vector2 newPositionVector = new Vector2();co
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()方法便可。上面的影響因子,可自行調節,以達到最優效果。