libGDX change tilemap

半腔热情 提交于 2021-01-28 12:10:41

问题


I am making an 2d rpg game with box2d. So, I've got a problem. When one of my bodies(the character) collides with another(a door) the map needs to change, should I just create new screens for maps and change them? Or is there a more simple solution?


回答1:


You can change your current map on the same screen only. What you have to do is, Let's say your map variable name is testMap. Now let's say your player just collided with a door. Now let's say you will call a method called changeMap(). Here is what you will put inside changeMap() method. (Assuming you are using tiled maps, you can change logic accordingly here)

void changeMap() {
    Gdx.app.postRunnable(() -> { //Post runnable posts the below task in opengl thread
        testMap = new TmxMapLoader().load("someMap.tmx"); //load the new map
        renderer.getMap().dispose(); //dispose the old map
        renderer.setMap(testMap); //set the map in your renderer
    });
}


来源:https://stackoverflow.com/questions/34599867/libgdx-change-tilemap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!