简体   繁体   中英

libGDX: Moving camera in Stage Viewport

I developed a libGDX application on Android that uses a Stage with Viewport and Camera. 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().translate()
anywhere, the camera position doesn't change.

I call stage.getViewport().getCamera().update() after these methods but nothing happens.

This problem was that, when I updated my Viewport in my ApplicationListener's resize function:

@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. To solve the problem set it to false , or remove it simply because that function has a 2 paramtered signature as well.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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