问题
My problem is that my FitViewport where i keep my game world, scales in a way that in the X axis i can see black bars, but the Y axis seems to not mind the Gdx.graphics limits and it goes out of the screen. What seems to be happening is that even though i pass it a World width and world height, it fits itself in a wrong way, not minding the Y axis at all.
PlayScreen constructor:
gameCamera = new OrthographicCamera();
gameCamera.setToOrtho(false);
gameViewport = new FitViewport(MyGame.WORLD_WIDTH,MyGame.WORLD_HEIGHT,gameCamera);
gameViewport.setScreenBounds(0,0,MyGame.WORLD_WIDTH,MyGame.WORLD_HEIGHT);
MyGame.java:
public static final int WORLD_WIDTH = 600;
public static final int WORLD_HEIGHT = 300;
render():
MyGame.batch.setProjectionMatrix(gameCamera.combined);
gameViewport.apply();
MyGame.batch.begin();
resize(int width, int height):
gameViewport.update(width,height);
gameCamera.position.set(player.position.x + 200,player.position.y, 0);
回答1:
The solution to this wasnt related to what i thought the problem was. The problem was that i was using wrong coordinate system and references to spawn enemies and bind the players movement. Now im using the gameViewport.getWorldHeight , and this solved my problem.
来源:https://stackoverflow.com/questions/35997011/fitviewport-doesnt-scale-properly-libgdx