2016-01-22 56 views
0

我正在使用LIBGDX進行遊戲。我從這裏繼續教程。一切正常,但我的輸出精靈位於屏幕的右上角。我試圖集中它,但我無法!我甚至調整了相機,但我失敗了。 這是我的屏幕上的代碼部分,Sprite出現在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的新手。提前致謝。

回答