简体   繁体   中英

My Tiled map is not being rendered in libgdx

I have spent the past couple of days trying to figure out what is wrong with my code. Im trying to render a tile map (.tmx) in libgdx but it does not render and it just shows a red screen with no error. I have re-written the code a few times and I always getting the same result.

my code:

public class Main extends ApplicationAdapter {
SpriteBatch batch;
TiledMap map;
TmxMapLoader loader;
OrthogonalTiledMapRenderer renderer;
OrthographicCamera camera;

@Override
public void create () {
    batch = new SpriteBatch();
    loader = new TmxMapLoader();
    map = loader.load("TiledMaps/TestMap.tmx");
    renderer = new OrthogonalTiledMapRenderer(map);
    camera = new OrthographicCamera();
    camera.setToOrtho(false,Gdx.graphics.getWidth(),Gdx.graphics.getHeight());

}

@Override
public void render () {
    Gdx.gl.glClearColor(1, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    camera.update();

    renderer.setView(camera);
    renderer.render();

    batch.begin();
    batch.end();
}

@Override
public void dispose () {
    batch.dispose();
    renderer.dispose();
    map.dispose();
}

}

Can anybody find what is happening here I have the tmx file with the tilesheet in the TileMaps folder in the android assets folder.

Any help is appreciated, Thanks in advance.

If I understand correctly, you're attempting something complex (map rendering) but encountering a simple problem (not rendering anything).

Have you got a simple program where you do have something rendering? Built it up so you have a few hard coded tiles rendering? Built it up a bit more to correctly read and display the first tile from the map? Before finally extending it further to read and display all the tiles, once you know the basics are working?

That's how I would tackle this problem. Been programming for years, and just used the same process to get CreateProcess working in C++ on Windows. Wasn't working within my code so I built an empty project that just runs CreateProcess on notepad.exe and tweaked things with answers from StackOverflow.com till I got it working, now it's about adding back in the other complications bit by bit so I'm not completely lost by taking on too much at once.

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