0
\$\begingroup\$

enter image description hereI used an orthographic camera to follow the character (player), but the problem is that my character is flipped. There are no tutorials on how to fix this. Please help as fast as possible.

Here is my create method:


public void create () {

    batch = new SpriteBatch();
    float width=Gdx.graphics.getWidth();
    float height=Gdx.graphics.getHeight();
    camera=new OrthographicCamera();
    camera.setToOrtho(false,width,height);
    camera.update();
    tiledMap= new TmxMapLoader().load("assets\\untitled.tmx");
    tiledMapRenderer=new OrthogonalTiledMapRenderer(tiledMap);
    player=new Player(new Vector2(0,0));
    sr= new ShapeRenderer();

}


Here is my render method: public void render () {

    Gdx.gl.glClearColor(0, 0, 0.2f, 1f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA,GL20.GL_ONE_MINUS_SRC_ALPHA);
    player.update();
    camera.position.set(player.getPosition().x,player.getPosition().y,0);
    camera.update();
    tiledMapRenderer.setView(camera);
    tiledMapRenderer.render();
    sr.begin(ShapeRenderer.ShapeType.Line);
    sr.setColor(Color.BLUE);
    sr.rect(player.getPosition().x,player.getPosition().y,player.getCurrentFrame().getRegionWidth(),player.getCurrentFrame().getRegionHeight());


    sr.end();
    batch.begin();

    batch.draw(player.getCurrentFrame(),player.getPosition().x, player.getPosition().y);
    batch.setProjectionMatrix(camera.combined);
    batch.end();
}
\$\endgroup\$
3
  • \$\begingroup\$ Can you add some screenshot? What you mean "flipped"? \$\endgroup\$
    – admund
    Jan 28, 2015 at 12:19
  • \$\begingroup\$ @AdmunD i add a screenshot \$\endgroup\$
    – Omar Taher
    Jan 30, 2015 at 6:21
  • \$\begingroup\$ Try changing the first parameter of camera.setToOrtho to true. If I remember correctly this is the flip y parameter. \$\endgroup\$ Jan 30, 2015 at 7:08

3 Answers 3

2
\$\begingroup\$

It's been a bit since I used LibGDX, but doesn't the setToOrtho function have a boolean that defines whether the camera is flipped or not? It looks like your whole screenshot is flipped, so instead of camera.setToOrtho(false, width, height); try using camera.setToOrtho(true, width, height);.

If it is just the player that is flipped (which I'm guessing is a sprite), you can just use player.flip(false, true) to flip it vertically.

\$\endgroup\$
1
  • \$\begingroup\$ i tried changing it several time true and false but the same and my player is a class \$\endgroup\$
    – Omar Taher
    Jan 30, 2015 at 7:25
0
\$\begingroup\$

the code above works but change camera.setToOrtho(false,width,height); to camera.setToOrtho(true,width,height); it was just that i had a resize method and had in it camera.setToOrtho(false,width,height);

\$\endgroup\$
0
\$\begingroup\$

If it is the entire viewport that is flipped; Similar to what QualityPixels' suggestion, I solved my issue with camera.setToOrtho(true, -width, height). You can flip the camera by setting the width and/or height to be negative. I would follow what he suggested if it's the character and not the viewport.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .