Read. TMX map

Source: Internet
Author: User

  
 
  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. }



From for notes (Wiz)

Read. TMX map

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.