我正在循环对象层,并且某些对象(在我的情况下是矩形地图对象(我想根据某些条件删除,但我看不到任何方法可以做到这一点。
有两种方法适用于您的用例:
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);
}