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