4
\$\begingroup\$

I'm using a little hack to change the coordinate system to the one i'm accustomed to (left and up is negative and right and down is positive) but this causes the tiled map renderer to render the map incorrectly, as shown below

Map rendered incorrectly

Whereas it looks like this in the Tiled map editor

Map rendered correctly

This is the "hack" I'm using to change the coordinate system:

float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();

Camera = new OrthographicCamera(w, h);
Camera.setToOrtho(true, w, h);

My render code

renderer.setView(Camera);
renderer.render();

So is there a workaround to this? Or perhaps a better way to change the coordinate system that doesn't screw up everything?

Edit: The rendered tiles are correct now but the map and everything rendering is still flipped along the y-axis. If I was drawing sprite and stuff, I could always draw them flipped but I don't know how to do it with the tiled map renderer.

\$\endgroup\$
  • \$\begingroup\$ Maybe there is a way to hack this easily, maybe not. If you are dead set on doing it your own way you will run into these issues often. --- Maybe consider ditching the outdated (archaic!) pixel buffer nostalgia and re-wiring your brain in a way that doesn't interfere with the way the rest of the world graphs things. \$\endgroup\$ – MickLH Oct 13 '13 at 23:59
5
\$\begingroup\$

seeing your both images i am sure that you are using following constructor for your code

randerer = new OrthogonalTiledMapRenderer(map);

this constructor set your map unit:pixel ratio 1:1. It is ok for non-side scrolling games but if you are planning to make a platformer side scrolling game you have to change the ratio so that you can move your camera.

replace the code with the second constructor like this

randerer = new OrthogonalTiledMapRenderer(map , 1/16f);

Now every unit of map is displaying the 16px So no set your camera to orthographic projection like this

camera.setToOrtho(false,width/16,height/16);

first parameter make y axis pointing upwords , width/16 and height/16 display the map in units(like 800px/16=50 units)

now set the

render.setView(camera);   

now see the whole code at once.....

@Override
public void show() {
    TmxMapLoader loader = new TmxMapLoader();
    map = loader.load("data/l.tmx");
    camera = new OrthographicCamera();
    renderer = new OrthogonalTiledMapRenderer(map,1/10f);
}

@Override
public void resize(int width, int height) {
    // TODO Auto-generated method stub

    camera.setToOrtho(false, width/10,height/10);



}


  @Override
 public void render(float delta) {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    renderer.render();
    camera.update();
    renderer.setView(camera);

            // to move the camera
    if(Gdx.input.isKeyPressed(Keys.A)){

            camera.position.x -=2;

    }
    if(Gdx.input.isKeyPressed(Keys.D)){

        camera.position.x +=2;

}
}
\$\endgroup\$
-2
\$\begingroup\$

use

Camera.setToOrtho(false, w, h);

it will flip your y axis to down

and renderer to

renderer.setView(camera.combined,0,0,width,height);
\$\endgroup\$
  • \$\begingroup\$ A comment explaining how and why this will help would greatly improve the quality of this answer. \$\endgroup\$ – Josh Oct 15 '13 at 16:17
  • \$\begingroup\$ I had tried @JoshPetrie with my little knowledge of english \$\endgroup\$ – Ravi Kumar Mistry Oct 15 '13 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.