问题描述
我的问题是,我保持游戏世界的FitViewport的缩放方式是,在X轴上我可以看到黑条,但是Y轴似乎不介意Gdx.graphics的限制,它超出了屏幕.似乎正在发生的事情是,即使我通过了世界宽度"和世界高度",它也以错误的方式适合自己,根本不介意Y轴.
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构造函数:
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:
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);
推荐答案
此解决方案与我认为的问题无关.问题是我使用错误的坐标系和参考来生成敌人并束缚玩家的动作.现在,我正在使用gameViewport.getWorldHeight,这解决了我的问题.
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.
这篇关于FitViewport无法正确缩放Libgdx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!