Viewport vp = new FitViewport(); vp.setScreenBounds(worldWidth / 2, worldHeight / 2, worldWidth, worldHeight); vp.apply();
/** * Uncomment the following viewports one at a time, and check out the effect when you resize the desktop window. */ @Override public void create() { camera = new OrthographicCamera(); // Makes the size of the world match the size of the screen viewport = new ScreenViewport(camera); // Make the world fill the screen, regardless of aspect ratio // viewport = new StretchViewport(WORLD_WIDTH, WORLD_HEIGHT, camera); // Make the world fill the screen, maintaining aspect ratio, but bits of the world may be cut off // viewport = new FillViewport(WORLD_WIDTH, WORLD_HEIGHT, camera); // Fit the world inside the screen, adding black bars to pad out the extra space, maintaining aspect ratio // viewport = new FitViewport(WORLD_WIDTH, WORLD_HEIGHT, camera); // Make the short axis of the world larger to fill the screen, maintaining aspect ratio // viewport = new ExtendViewport(WORLD_WIDTH, WORLD_HEIGHT, camera); viewport.setScreenBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); renderer = new ShapeRenderer(); }
@Override public void resize(int width, int height) { final World world = ui.getWorld(); if (!world.isDisposed()) { screenViewport.setWorldSize(world.getWidth(), world.getHeight()); screenViewport.update(width, height, true); worldViewport.setScreenBounds(screenViewport.getScreenX(), screenViewport.getScreenY(), screenViewport.getScreenWidth(), screenViewport.getScreenHeight()); world.resize(screenViewport.getWorldWidth(), screenViewport.getWorldHeight()); } pointer.resize(); verbUI.setSize(screenViewport.getScreenWidth(), screenViewport.getScreenHeight() * UI_SCREEN_PERCENT); float size = DPIUtils.getPrefButtonSize(); float margin = DPIUtils.getMarginSize(); menuButton.setSize(size, size); menuButton.setPosition(stage.getViewport().getScreenWidth() - menuButton.getWidth() - margin, stage.getViewport().getScreenHeight() - menuButton.getHeight() - margin); }
aiViewport.setScreenBounds((int) indicatorx, (int) indicatory, (int) indicatorw, (int) indicatorh); aiViewport.apply(); aiViewport.setScreenBounds(0, 0, rw, rh); aiViewport.apply();
extendViewport.setScreenBounds(0, 0, rw, rh); extendViewport.apply(); viewport.setScreenBounds(0, 0, boundsw, boundsh); viewport.apply(); viewport.setScreenBounds(start2w, start2h, boundsw, boundsh); viewport.apply(); viewport.setScreenBounds(0, 0, rw, rh);
viewport.setCamera(cam); viewport.setWorldSize(wh, wh); viewport.setScreenBounds(0, 0, wh, wh); viewport.apply();