【问题标题】:LibGdx MapProperties object method containsKey always returns falseLibGdx MapProperties 对象方法 containsKey 始终返回 false
【发布时间】:2019-05-25 03:39:12
【问题描述】:

我正在研究 LibGdx 框架,使用 Tiled 地图编辑器创建和使用 TmxMapLoader() 读取地图的 .tmx 数据的 TiledMap 类,但 MapProperties 类的方法 containsKey 在 if 语句中失败

我已经尝试保存加载 tmx 文件平铺编辑器,有趣的是我得到了 MapObjects getCount() 对。

TiledMap map;
//...
map = new TmxMapLoader().load("maps/32/level0.tmx");
//...
MapLayer layer = map.getLayers().get(2);
   MapObjects objects = layer.getObjects();
   System.out.println(objects.getCount());  
// objects.getCount() returns 2 or 3 when i change items via editor
   MapObject  object = objects.get(0);
// Entity entity;  // omitted for testing 
   MapProperties prop = object.getProperties();
   if (prop.containsKey("type")){ 
       // ignored (always false) , i got 2 objects both with property
       // type 1 and type 2
       int i = prop.get("type", int.class);
       System.out.println(i);
    // entity = Entity.GetValue(i); // omitted for testing 
    // System.out.println(entity); // omitted for testing 
       // the goal is to store tile object types in Entity enum
   }

在 if 中预期为真,但始终为假,

编辑:我添加了方法描述,也许我误解了一些东西 https://libgdx.badlogicgames.com/ci/nightlies/docs/api/com/badlogic/gdx/maps/MapProperties.html#containsKey-java.lang.String-

【问题讨论】:

  • 我测试了 "typeZ" 而不是 "type" ,仍然没有
  • type != (type 1 || type 2)
  • @icarumbas 你用过平铺地图编辑器吗?

标签: java libgdx


【解决方案1】:

Tile Map Editor save problem (embed tileset inside tmx file) ,java代码没问题。 如果有人对 tileSets 有问题,请提供一些信息。

  • Tile Map Editor 的 MAP 文件扩展名为 *.tmx
  • Tile Map Editor 的 tileSet 文件扩展名为 *.tsx

永远不要使用 embed tileset 保存,你应该单独保存 tmx 和 tsx 文件

【讨论】:

    猜你喜欢
    • 2012-10-04
    • 1970-01-01
    • 1970-01-01
    • 2016-10-15
    • 2011-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多