在LIBGDX中屏幕右上角出现的精灵
我正在使用LIBGDX开发一个游戏。我遵循这个教程。一切都很好,但我的输出精灵在屏幕的右上角。我试着把它放在中心,但我不能!我甚至调整了照相机,但我失败了。 这是我的部分屏幕代码在LIBGDX中屏幕右上角出现的精灵,libgdx,screen,Libgdx,Screen,我正在使用LIBGDX开发一个游戏。我遵循这个教程。一切都很好,但我的输出精灵在屏幕的右上角。我试着把它放在中心,但我不能!我甚至调整了照相机,但我失败了。 这是我的部分屏幕代码 public PlayScreen(MyGame game) { this.game = game; this.gamecam = new OrthographicCamera(); this.gamePort = new FitViewport(MyX.V_WIDTH / MyXGame.PP
public PlayScreen(MyGame game) {
this.game = game;
this.gamecam = new OrthographicCamera();
this.gamePort = new FitViewport(MyX.V_WIDTH / MyXGame.PPM, MyX.V_HEIGHT / MyXGame.PPM, gamecam);
this.hud = new HudClass(game.batch);
loader = new TmxMapLoader();
map = loader.load("tiledmap.tmx");
renderer = new OrthogonalTiledMapRenderer(map, 1 / MyJungleGame.PPM);
gamecam.position.set(gamePort.getWorldWidth() / 2, gamePort.getWorldHeight() / 2, 0);
world = new World(new Vector2(0, -10), true);
b2dr = new Box2DDebugRenderer();
creator = new B2WorldCreator(this);
gamehero = new Hero(this);
world.setContactListener(new WorldContactListener());
items = new Array<Item>(); //initializing things
itemsToSpawn = new LinkedBlockingQueue<ItemDef>();
}
我已经附上了输出的屏幕截图
据我所知,问题在于在playscreen中设置摄像头。但我不知道如何解决它。请帮助我,我是LIBGDX新手。提前谢谢。
这是我能给你的最好的帮助。希望它能有所帮助。此外,我鼓励您编写和设计更好的代码,因为它有点难读
干杯
public void render(float delta) {
this.update(delta);
Gdx.gl.glClearColor(1, 0, 0, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
renderer.render();
b2dr.render(world, gamecam.combined);
game.batch.setProjectionMatrix(this.gamecam.combined);
game.batch.begin();
gamehero.draw(game.batch);
for (Goomba enemy : creator.getGoombas())
enemy.draw(game.batch);
for(Item item :items)
item.draw(game.batch);
game.batch.end();
game.batch.setProjectionMatrix(hud.stage.getCamera().combined);
hud.stage.draw();
}