有没有办法从平铺地图中删除对象?

时间:2018-09-18 06:28:08

标签: libgdx tiled tmxtiledmap

我正在遍历对象层,并且有某些对象(在我的情况下为Rectangle Map对象),我想根据特定条件将其删除,但是我看不到有任何方法可以这样做。

1 个答案:

答案 0 :(得分:1)

您的用例有两种方法:

  • com.badlogic.gdx.maps.MapObjects#remove(com.badlogic.gdx.maps.MapObject)
  • com.badlogic.gdx.maps.MapObjects#remove(int)

请参见https://libgdx.badlogicgames.com/ci/nightlies/docs/api/com/badlogic/gdx/maps/MapObjects.html

所以我想你会做这样的事情:

            ArrayList<MapObject> objectsToRemove = new ArrayList<>();

            for (MapObject object : mapLayer.getObjects()) {
                if (object.getName().contains("removeMe")) // TODO
                {
                    objectsToRemove.add(object);
                }
            }
            for (MapObject mapObject : objectsToRemove) {
                mapLayer.getObjects().remove(mapObject);
            }