简体   繁体   English

libGDX:在舞台视口中移动相机

[英]libGDX: Moving camera in Stage Viewport

I developed a libGDX application on Android that uses a Stage with Viewport and Camera. 我在Android上开发了一个libGDX应用程序,该应用程序使用带有视口和摄像头的舞台。 I wanted to change the viewport's camera position, but nothing happens. 我想更改视口的摄影机位置,但没有任何反应。 I didn't know what can cause this problem. 我不知道什么会导致这个问题。

If I change 如果我改变
stage.getViewport().getCamera().position.x or I call stage.getViewport().getCamera().position.x或我打电话
stage.getViewport().getCamera().translate()
anywhere, the camera position doesn't change. 在任何地方,相机位置都不会改变。

I call stage.getViewport().getCamera().update() after these methods but nothing happens. 在这些方法之后,我调用stage.getViewport().getCamera().update() ,但没有任何反应。

This problem was that, when I updated my Viewport in my ApplicationListener's resize function: 问题是,当我在ApplicationListener的resize函数中更新视口时:

@Override
    public void resize(final int width, final int height) {
        stage.getViewport().update(width, height, false);
    }

I set the third parameter to true and this way the camera is recentered all the time, and my calls were ineffective. 我将第三个参数设置为true ,这样摄像机就一直保持更新状态,并且我的通话无效。 To solve the problem set it to false , or remove it simply because that function has a 2 paramtered signature as well. 要解决该问题,请将其设置为false ,或者仅由于该函数也具有2个参数签名而将其删除。

I share this problem because it was difficult for me to find out what's going on, and this might spare some time for others in the same situation. 我遇到了这个问题,因为我很难发现正在发生的事情,这可能会为处于相同情况的其他人节省一些时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM