i´m currently working on a Android game with the library libgdx. Currently I m facing a problem, where the xy-coordinate system is flipt.
I did some research and found that if you use a OrthographicCamera you can change the y coordinate so its no longer flipt.
Code:
public class Game extends ApplicationAdapter {
Miner miner;
SpriteBatch batch;
TouchManager touchManager;
OrthographicCamera camera;
public void create(){
camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
miner = new Miner(new Texture(Gdx.files.internal("miner_lv1.png")), 0, 0, 200, 200);
batch = new SpriteBatch();
touchManager = new TouchManager();
}
public void render(){
//update
camera.update();
touchManager.update(camera);
miner.update();
//drawing
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(Gdx.gl20.GL_COLOR_BUFFER_BIT);
batch.begin();
miner.render(batch);
batch.end();
}
public void dispose()
{
batch.dispose();
miner.dispose();
}
}
Miner:
public class Miner extends Entity {
public Miner(Texture texture, int x, int y, int width, int height) {
super(texture, x, y, width, height);
}
@Override
public void update() {
sprite.setX(x);
sprite.setY(y);
}
@Override
public void render(SpriteBatch batch) {
sprite.draw(batch);
}
@Override
public void dispose() {
texture.dispose();
}
}
The output is as following: Ouptut of code
My question is how do i change the coordinate system that x = 0 and y = 0 is in the top left corner.
Thank you in advance!