我正在使用TmxMapLoader,我似乎找不到从* .tmx读取折线数据的方法。
TmxMapLoader mapLoader = new TmxMapLoader();
TiledMap map = mapLoader.load("map1.tmx");
MapLayers layers = map.getLayers();
Iterator<MapLayer> layersIter = layers.iterator();
while(layersIter.hasNext()) {
MapLayer layer = layersIter.next();
if(layer.getName().equals("path")) {
MapObjects os = layer.getObjects();
Iterator<MapObject> osIter = os.iterator();
while(osIter.hasNext()) {
MapObject o = osIter.next();
MapProperties p = o.getProperties();
// p.get("x") p.get("y") - <object x="" y""> works just fine
// but how can I get all polyline data from <polyline>?
}
}
}
* .tmx文件的相关部分:
<objectgroup color="#9da0a4" name="path">
<object x="9.09091" y="1509.09">
<polyline points="0,0 1,1"/>
</object>
</objectgroup>
我检查了TmxMapLoader的代码,似乎已经实现了这个功能,但我找不到一种方法来获取它。
有什么想法吗?
答案 0 :(得分:2)
您可以按照以下方式获取折线,其中o
是MapObject
:
Polyline polyline = ((PolylineMapObject)o).getPolyline();
请记住,您可能之前检查过实例以防止出现ClassCastException
if(o instanceof PolylineMapObject) {
Polyline polyline = ((PolylineMapObject)object).getPolyline();
.....
}
希望这有帮助。