2014-06-07 22 views
1

http://badlogicgames.com/forum/viewtopic.php?f=11&t=2447 http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/OrthographicCamera.html設置的applcation在LibGDX使用「Y-下」

有數以百計的其他環節,我可以告訴你,我已經看了,但它只是不值得的,因爲他們都說着同樣的事情。

public class InGame implements Screen { 

    SpriteBatch batch; 
    GameWorld world; 
    OrthographicCamera camera; 

    @Override 
    public void show() { 
     batch = new SpriteBatch(); 
     world = new GameWorld(); 
     camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); 
     camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); 
    } 


    @Override 
    public void render(float delta) { 
     Gdx.gl.glClearColor(0f, 0f, 0f, 1f); 
     Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 
     camera.update(); 
     batch.setProjectionMatrix(camera.combined); 

     batch.begin(); 
      world.render(batch, delta); 
     batch.end(); 

    } 
} 

我在做什麼錯?爲什麼我的世界仍然在0,0在右下方呈現。在嘗試使用我的瓷磚系統時,背後的數學讓我絕對瘋了。

世界 - >渲染

public void render(SpriteBatch batch, float delta) { 
    for(int xAxis = 0; xAxis < worldColumns; xAxis++) { 
     for(int yAxis = 0; yAxis < worldRows; yAxis++) { 
      tiles[xAxis][yAxis].render(batch, delta); 
     } 
    } 
} 

WorldTile->渲染

public void render(SpriteBatch batch, float delta) { 
     myShape.begin(ShapeType.Filled); 
     myShape.setColor(tileColor); 
     myShape.rect(pos.getX(), pos.getY(), TILE_WIDTH, TILE_HEIGHT); 
     myShape.end(); 
    } 

的 「POS」 是已在世界類傳入的位置(x,y)的。

回答

0

如果使用SpriteBatch繪製Sprite或TextureRegion,代碼應該可以正常工作。但是,您將SpriteBatch批次傳遞到WorldTile.render並從不使用它?!相反,你使用myShape,我認爲它是一個ShapeRenderer。您需要爲ShapeRenderer設置投影矩陣,否則將繪製「顛倒」。 在使用myShape之前,請嘗試調用myShape.setProjectionMatrix(camera.combined);

它最好在InGame類中聲明和初始化myShape,使用myShape.setProjectionMatrix(camera.combined);,然後像使用SpriteBatch一樣將myShape傳遞給tiles.render()。

希望這會有所幫助。