简体   繁体   中英

Orthographic camera and Stage

I'm using libgdx 1.1.

Is it possible set the orthographic camera for the Stage in scene2d? I need it to add button in my app and at the same time to support different screen resolution.

I've tried this code to adapt the screen:

camera = new OrthographicCamera();
camera.setToOrtho(false, x, y);
batch = new SpriteBatch();

What you are doing is not correct. Nowadays you create a viewport depending on what you need. (There are several) While creating your stage you add the viewport to it. The viewport itself holds the camera. You can optain that camera by getCamera()

You create the viewport with your camera.

So here is how it could look like:

camera = new OrthographicCamera();
camera.setToOrtho(false, x, y);
FitViewport viewp = new FitViewport(x, y, camera); // change this to your needed viewport
batch = new SpriteBatch();
Stage s = new Stage(viewp, batch); //also pass the singelton batch here. Try just to use onee batch to have a good performance.

Here is some further information out of the libgdx forum about this.

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