Thank you, I’ve been playing with this; However the LibGDX Y axis flip is driving me absolutely insane. I’ve done my own math to try to calculate for it, but every step I take seems like it’s in the wrong direction.
I read that using the Orthographic Camera I can easily make the Y position 0 at the top left like it is in Java2D, however that doesn’t seem to be the case, either that or I’m missing something very simple.
Here’s my code:
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);
batch.setProjectionMatrix(camera.combined);
batch.begin();
world.render(batch, delta);
batch.end();
}
If you need anything other than this let me know, the tiles are still drawing from the bottom left.
No, I’m not using tiledmap. If you’re curious as to how I’m drawing my tiles
Generating the tile world:
private void placeTiles() {
for(int xAxis = 0; xAxis < worldColumns; xAxis++) {
for(int yAxis = 0; yAxis < worldRows; yAxis++) {
tiles[xAxis][yAxis] = new GameTile(
GameTile.getTypeForID(mapData[yAxis][xAxis]),
new Position(xAxis * GameTile.TILE_WIDTH, yAxis * GameTile.TILE_HEIGHT));
}
}
}
Render method for tile:
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();
}