Jump to content
  • Advertisement
macmanmatty

Java how to properly link an OrthographicCamera to a OrthogonalTiledMapRenderering libGDX

Recommended Posts

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);

}

Share this post


Link to post
Share on other sites
Advertisement

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?????

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!