【问题标题】:libGDX change tilemaplibGDX 更改 tilemap
【发布时间】:2016-12-08 13:27:01
【问题描述】:

我正在使用 box2d 制作 2d rpg 游戏。所以,我有一个问题。当我的一个身体(角色)与另一个(一扇门)碰撞时,地图需要改变,我应该为地图创建新屏幕并改变它们吗?还是有更简单的解决方案?

【问题讨论】:

    标签: libgdx tile


    【解决方案1】:

    您只能在同一屏幕上更改当前地图。您要做的是,假设您的地图变量名称是testMap。现在假设你的玩家刚刚撞到了一扇门。现在假设您将调用一个名为changeMap() 的方法。这是您将在 changeMap() 方法中放入的内容。 (假设您使用的是平铺地图,您可以在此处相应地更改逻辑)

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-03
      • 1970-01-01
      • 2017-07-02
      • 1970-01-01
      • 2014-12-01
      • 2014-03-04
      相关资源
      最近更新 更多