精灵出现在LIBGDX屏幕的右上角

时间:2016-01-22 13:50:05

标签: libgdx screen

我正在使用LIBGDX进行游戏。我正在按照这个教程。一切都很好,但我的输出精灵位于屏幕的右上角。我试图将它集中在一起,但我无法做到!我甚至调整了相机,但我失败了。    这是我的屏幕代码部分,

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>();
}

我的渲染方法,

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();
}

我已附上输出的屏幕截图。 output

据我所知,问题在于在播放屏幕中设置相机。但我不知道如何解决它。请帮助我是LIBGDX的新手。提前谢谢。

1 个答案:

答案 0 :(得分:0)

https://github.com/libgdx/libgdx/wiki/Orthographic-camera

这是我能给你的最好帮助。希望它有所帮助。另外,我鼓励你编写和设计更好的代码,它有点难以阅读。

干杯。