0
\$\begingroup\$

how to properly link an OrthographicCamera to a OrthogonalTiledMapRenderer

How do I properly link an OrthographicCamera to a OrthogonalTiledMapRenderer? I have tiled map i'd like render and two stages that have actors on them.. I call render.render() in my screens render method as well as stages.draw(); but every i put render.setView(camera) the screen displayed flashes or does other weird things. How do I properly attach a moveable camera to a tiled map renderer? I render the map first, do game logic and then call draw on the stages. when I call translate on the camera the tiled map zooms way out for some reason?

here is my render method

public void render(float delta) {

    Gdx.gl.glClearColor(1, 0, 0, 1);
        Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        camera.update();
        renderer.render();





        gameLogic();


        backStage.act(); // acts are called but do nothing


        frontStage.act();

        frontStage.draw();
        backStage.draw();

}

here is where the camera and renderer get created

public void addMap(GameMap map){

this.map=map;
maps.add(map);
    renderer=new OrthogonalTiledMapRenderer(map.getTiledMap(), 1/20f);
    camera= new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    float aspect = Gdx.graphics.getWidth()/Gdx.graphics.getHeight();
    camera.setToOrtho(false, 20*aspect, 20*aspect);


    renderer.setView(camera);
    frontStage= new Stage();
    backStage=new Stage();

    xSize=map.getXSize();
    ySize=map.getYSize();
    Gdx.input.setInputProcessor(this);

}
\$\endgroup\$
2
  • \$\begingroup\$ I solved my problem I took someones working code to make the camera move which was 100% the same as mine made a new class tried running it . It worked!! Then I slowly added more of code testing each time until I was 100% of my previous code that did not work. The only thing I changed is I now have a new source code file (the class name is still the same though). Making a new class solved withe same code solved my problem????? \$\endgroup\$ Nov 21 '18 at 16:19
  • \$\begingroup\$ You must call renderer.setView(camera); in the render method so it will call every frame \$\endgroup\$
    – Morchul
    Nov 23 '18 at 14:41
0
\$\begingroup\$

I solved my problem I took someones working code to make the camera move which was 100% the same as mine made a new class tried running it . It worked!! Then I slowly added more of code testing each time until I was 100% of my previous code that did not work. The only thing I changed is I now have a new source code file (the class name is still the same though). Making a new class solved with the same code solved my problem?????

\$\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.