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\$
  • \$\begingroup\$ Can you add some screenshot? What you mean "flipped"? \$\endgroup\$ – admund Jan 28 '15 at 12:19
  • \$\begingroup\$ @AdmunD i add a screenshot \$\endgroup\$ – Omar Taher Jan 30 '15 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\$ – tom van green Jan 30 '15 at 7:08
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.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ i tried changing it several time true and false but the same and my player is a class \$\endgroup\$ – Omar Taher Jan 30 '15 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);

| improve this answer | |
\$\endgroup\$

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.