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)的。