FitViewport doesnt scale properly Libgdx

╄→гoц情女王★ 提交于 2020-01-06 03:12:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!