简体   繁体   中英

Libgdx tiledmap not displaying properly

I have been trying to get tiled map displayed for small game I am making, scoured internet for answers, but didn't have any luck. I have tried to do it the easiest way by copying tutorial code and just changing source of the file which still left me stuck with not displaying properly the tiled map.

Here is the code.

    Texture img;
    TiledMap tiledMap;
    OrthographicCamera camera;
    TiledMapRenderer tiledMapRenderer;

    @Override
    public void create () {
        float w = Gdx.graphics.getWidth();
        float h = Gdx.graphics.getHeight();

        camera = new OrthographicCamera();
        camera.setToOrtho(false,w,h);
        camera.update();
        tiledMap = new TmxMapLoader().load("mapFull.tmx");
        tiledMapRenderer = new OrthogonalTiledMapRenderer(tiledMap, 1/1f);
    }

    @Override
    public void render () {
        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();
        tiledMapRenderer.setView(camera);
        tiledMapRenderer.render();
    }

This is the outcome of the code when I run it.

This is what it looks like in tiledMapEditor

I could really use any help just to get it running. As I plan to add it to Scene2D but now I cant even get basic running.

Edit

So it seems there is some issue with the way the libgdx is displaying tiled map on monitor. It does display correctly only if I use 1 tile style. Different tile just doesn't show. I tried even loading pre-made tiledmap from tiledMapEditor and even those fail to load properly.

edit2:So now I have 2 different layers it got little bit better as there was issue with different size of tiles which stretched it all over. The problem now is that libgdx doesn't render tiledmap properly on screen still, only 1 type of tile is shown, the second is just ignored.

This is what is rendered:

这就是渲染的内容。

This is what it should looked like:

这就是它应该的样子

I have installed newer version of eclipse that resolved the issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM