读取.tmx地图

  1. 读取.tmx地图
  2. m_GameMap = CCTMXTiledMap::create("map1.tmx");
  3. this->addChild(m_GameMap,1);
  4. 读取对象数组
  5. bool bFlag = false;
  6. //获取对象层
  7. TMXObjectGroup *group = getGameMap()->objectGroupNamed("coll");
  8. //通过对象名获取该对象层对象
  9. auto player = group->getObject("monst1");
  10. //获取改对象层数组
  11. auto coll = group->getObjects();
  12. for (int i = 0; i < coll.size(); i++)
  13. {
  14. auto& obj = coll.at(i);
  15. ValueMap& dict = obj.asValueMap();
  16. //获取name属性
  17. //std::string name = dict["name"].asString();
  18. //获取x,y属性
  19. float x = dict["x"].asFloat();
  20. float y = dict["y"].asFloat();
  21. //获取width,height属性
  22. float width = dict["width"].asFloat();
  23. float height = dict["height"].asFloat();
  24. Rect box = Rect(x, y, width, height);
  25. }


上一篇:阿里云ECS服务器,CentOS 7.4配置jdk+tomcat+mysql


下一篇:阿里云ECS主机多个网站配置,是有先后顺序的