Libgdx相机位置和缩放捕捉到位置而不是平滑动画

时间:2015-03-13 21:25:50

标签: java camera libgdx android-camera

我尝试在libgdx中实现平滑的相机缩放方法,其中方法缩放在缩放量的两个值之间插值,即初始*最终。 但问题是,当变焦或移动时,相机会快速捕捉到位置。如何创建一个流畅的相机类并实现缩放而不会有一个跳动的scrren?

private void panZoom(Vector3 spanCord, TweenManager tweenManager, GameWorld world)
    {
            /*
             * Example Tween-Sequence: Zoom to 120%, Pan to point of interest #1 (0, -50), Wait 1 second, Pan back to the
             * starting position, Zoom back to the initial value
             */
            Timeline.createSequence()
                .beginParallel()
                .push(Tween.to(this, OrthographicCameraAccessor.POSITION, 3.5f).target(spanCord.x,spanCord.y,spanCord.z).ease(Elastic.OUT))
                .push(Tween.to(this, OrthographicCameraAccessor.ZOOM, 3.5f).target(1.20f).ease(Elastic.OUT))
                .end()

                .beginParallel()
                .push(Tween.to(this, OrthographicCameraAccessor.POSITION, 2.8f).target(world.getYoyo().position.x,0,0).ease(Bounce.INOUT))
                .push(Tween.to(this, OrthographicCameraAccessor.ZOOM, 3.0f).target(1).ease(Bounce.INOUT))
                .end()
                .start(tweenManager);
    }




    public float calcZoom(float initialDistance, float distance)
    {
        float nextZoom;

        if(initialDistance < distance)
        {
            float ratio = (initialDistance/distance)/10;
            nextZoom = zoomIn(ratio);
        }
        else
        {
            float ratio = (distance/initialDistance)/10;
            nextZoom = zoomOut(ratio);
        }

        return nextZoom;
    }


public class OrthographicCameraAccessor implements TweenAccessor<MyOrthographicCamera> {

    /** Tween position */
    public static final int POSITION = 1;
    /** Tween zoom */
    public static final int ZOOM = 2;

    /**
     * @param camera
     * camera to get values from
     * @param tweentype
     * type of tween (Position or Zoom)
     * @param returnValues
     * out parameter with the requested values
     */
    @Override
    public int getValues(MyOrthographicCamera camera, int tweenType, float[] returnValues)
    {
        switch (tweenType)
        {
            case POSITION:
                returnValues[0] = camera.position.x;
                returnValues[1] = camera.position.y;
                returnValues[2] = camera.position.z;
                return 3;
            case ZOOM:
                returnValues[0] = camera.zoom;
                return 1;
            default:
                return 0;
        }
    }

    /**
     * @param camera
     *  camera whose some values are going to be set
     * @param tweenType
     * Position or Zoom
     * @param newValues
     *  array containing the new values to configure the camera
     */
    @Override
    public void setValues(MyOrthographicCamera camera, int tweenType, float[] newValues)
    {
        switch (tweenType)
        {
            case POSITION:
                camera.setPosition(newValues[0], 0);
                camera.update();
                break;
            case ZOOM:
                camera.setZoom(newValues[0]);
                camera.update();

                Gdx.app.log("CAMERA", "Clamped Zoom" +camera.zoom);
                break;
            default:
                break;
        }
    }

0 个答案:

没有答案