Search code examples
androidlocationlandscapepointlibgdx

LibGDX Landscape orientation X and Y as location 0,0


Anyone know if it's possible to set the upper left corner of the Android device as 0,0? As of now, it seems the location is (on my HTC desire) X: 320, Y: 0. I want it to be 0,0.

Anyone know if it's possible? Or how to. As I'm placing a lot of tiles, that later will also use the X and Y positions, I find it favorable that the top left corner is 0,0.


Solution

  • You need to look into using cameras.

    OrthographicCamera camera;
    camera = new OrthographicCamera((float) 100, (100 * (9.0f/16.0f) ));    //UI
    camera.position.set(0f, 0f, 0);
    

    I typically store that camera somewhere, and then you need to apply it to the spritebatch each time your render loops.

    applyCamera(spriteBatch, camera);
    GfxD.spriteBatch.begin();{
        for(Sprite4 sprite: SpriteList) {   sprite.draw(spriteBatch);   }
    }GfxD.spriteBatch.end();
    

    ...and my "apply camera" method looks like...

    public static void applyCamera  (SpriteBatch spritebatch, OrthographicCamera camera){
        camera.update();
        spritebatch.getProjectionMatrix().set(camera.combined);
    }
    

    You will have to edit the code for your own purposes, but hopefully that should get you started in the right direction.