Hello. The problem is visible in the pictures. When the resolution of the program is 800x600, everything seems to be normal. But if you expand the program, the buttons become big! If you click on the Screen_2 button (there is the same screen), the buttons are reduced! How to make it so that when you maximize the window at once everything is applied, and not when you press a button? In general, I haven't done anything for a week with this. Google also did not help. So I decided to write here suddenly someone can help. I spread screenshots and all code: one screentwo screen The main class runs with a resolution of 800x600:

public class RunGame extends Game { public SpriteBatch batch; public BitmapFont font; TestCamera camera1; TestCamera2 camera2; @Override public void create() { batch = new SpriteBatch(); font = new BitmapFont(); camera2 = new TestCamera2(this); setScreen(camera1 = new TestCamera(this)); } @Override public void resize(int width, int height) { super.resize(width, height); } @Override public void render() { super.render(); } } 

Class of the first screen:

  public class TestCamera implements Screen { final RunGame runGameTest; private Texture backText; private Skin skin; private Stage stage; private OrthographicCamera camera; private TextButton buttonNewGame; private TextButton buttonOptions; private TextButton buttonExit; public TestCamera(final RunGame runGameTest) { this.runGameTest = runGameTest; camera = new OrthographicCamera(); } @Override public void show() { backText = new Texture(Gdx.files.internal("menu/menuScreen/background.jpg")); skin = new Skin(Gdx.files.internal("fonts/uiskin.json")); stage = new Stage(); buttonNewGame = new TextButton("--------", skin, "default"); buttonOptions = new TextButton("Screen_2", skin, "default"); buttonExit = new TextButton("--------", skin, "default"); buttonNewGame.setWidth(200f); buttonNewGame.setHeight(50f); buttonNewGame.setPosition(50, 240); buttonOptions.setWidth(200f); buttonOptions.setHeight(50f); buttonOptions.setPosition(50, 300f); buttonExit.setWidth(200f); buttonExit.setHeight(50f); buttonExit.setPosition(50, 360f); buttonNewGame.addListener(new ClickListener(){ @Override public void clicked(InputEvent event, float x, float y){ } }); buttonOptions.addListener(new ClickListener(){ @Override public void clicked(InputEvent event, float x, float y){ ((Game)Gdx.app.getApplicationListener()).setScreen(runGameTest.camera2); } }); buttonExit.addListener(new ClickListener(){ @Override public void clicked(InputEvent event, float x, float y){ Gdx.app.exit(); } }); stage.addActor(buttonNewGame); stage.addActor(buttonOptions); stage.addActor(buttonExit); Gdx.input.setInputProcessor(stage); } @Override public void render(float delta) { Gdx.gl.glClearColor(0, 0, 0.0f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); runGameTest.batch.setProjectionMatrix(camera.combined); camera.update(); runGameTest.batch.begin(); runGameTest.batch.draw(backText, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); runGameTest.font.draw(runGameTest.batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), Gdx.graphics.getWidth()-76, Gdx.graphics.getHeight()-20); runGameTest.font.draw(runGameTest.batch, "FULL SCREEN: F4 ", Gdx.graphics.getWidth()-150, Gdx.graphics.getHeight()-40); runGameTest.batch.end(); stage.act(); stage.draw(); } @Override public void resize(int width, int height) { camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); stage.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true); camera.update(); } @Override public void dispose() { Gdx.input.setInputProcessor(null); backText.dispose(); stage.dispose(); skin.dispose(); } @Override public void pause() { } @Override public void resume() { } @Override public void hide() { } } 

The second screen is identical to the first! I ask to help who faced this problem.

    1 answer 1

    Try this:

     stage = new Stage(new ScreenViewport()); 
    • Yes, thanks, I already wanted to write it here and forgot ... I did it this way ... but only the camera had to be moved to the main class ... now everything works. Thanks for answering. +1 - dev3java