在缩放时保持演员大小

时间:2015-12-18 14:09:42

标签: android libgdx opengl-es-2.0

我试图在地图上绘制用户位置指示器(这是一个演员),无论是透视摄像机视野,因此在放大时,演员的大小将保持不变。

我尝试过以下代码,但没有成功:

userActorContainer.setScale(camera.fieldOfView/150,camera.fieldOfView/150);

编辑1: 好吧,我已经使用单独的SpriteBatch来渲染用户位置指示器,现在大小问题是固定的,但正如我预测的那样,演员的位置是完全错误的(不适合背景缩放的地图)。这是我的代码:

在构造函数中:

    camera.update();
    firstProjectionMatrix = new Matrix4();
    firstProjectionMatrix.set(camera.combined);

在渲染方法中:

    testBatch.setTransformMatrix(camera.view);
    testBatch.setProjectionMatrix(firstProjectionMatrix);
    testBatch.begin();
    pinsGroup.draw(testBatch, 1);
    testBatch.end();

1 个答案:

答案 0 :(得分:0)

只需将此演员添加到另一个舞台 - 然后您可以使用地图对舞台进行缩放,这对您的演员不起作用

    Stage mapStage, actorStage;

    ...

    //render method
    mapStage.handleZoom(); //you zooming handling here
    mapStage.act();
    mapStage.draw();

    actorStage.act();
    actorStage.draw();

请注意,您还可以在actorStage上使用其他类型的视口/摄像头,这也非常有用

如果您不使用Scene2D,您还可以创建第二个摄像头,并在指示器渲染之前将其。组合设置为spriteBatch,或者甚至仅为指示器创建新的SpriteBatch渲染目的如

    SpriteBatch batch, indicatorBatch;

    ...

    //render()
    camera.update();

    batch.setProjectionMatrix(camera.combined);

    batch.begin();
    //rendering map etc...
    batch.end();

    indicatorBatch.begin();
    //rendering indicator
    indicatorBatch.end();    

编辑 - 要在缩放相机后处理位置,您应该使用camera project and unproject方法。 You can also read more here

相关问题