【问题标题】:How to read polyline cords from a *.tmx file?如何从 *.tmx 文件中读取折线?
【发布时间】:2015-01-14 11:37:24
【问题描述】:

我正在使用 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 的代码,它似乎已经实现了这个功能,但我找不到获得它的方法。

有什么想法吗?

【问题讨论】:

  • 折线折线 = ((PolylineMapObject)o).getPolyline();?
  • 我可以吻你吗? ;-) 谢谢!虽然不是最好的设计。
  • 呵呵呵呵,哦不!!!,不客气:)
  • @vzamanillo 也许将其作为答案发布?
  • @Thorbjørn,你明白了,干杯。

标签: java libgdx tmx tiled


【解决方案1】:

您可以按如下方式获取折线,其中oMapObject

Polyline polyline = ((PolylineMapObject)o).getPolyline();

请记住,您之前可能已经检查过实例以防止 ClassCastException

if(o instanceof PolylineMapObject) {
    Polyline polyline = ((PolylineMapObject)object).getPolyline();
    .....
}

希望这会有所帮助。

【讨论】:

猜你喜欢
  • 2017-10-01
  • 2017-11-04
  • 1970-01-01
  • 2017-05-29
  • 2022-01-11
  • 1970-01-01
  • 1970-01-01
  • 2014-03-15
  • 2012-12-16
相关资源
最近更新 更多