tilemap在cocos2dx-3.x中的使用

 <objectgroup name="Objects" width="27" height="20">
  <object name="Waypoint0" x="887" y="292"/>
  <object name="Waypoint1" x="438" y="296"/>
  <object name="Waypoint2" x="429" y="22"/>
  <object name="Waypoint3" x="22" y="23"/>
  <object name="Waypoint4" x="24" y="493"/>
  <object name="Waypoint5" x="433" y="497"/>
  <object name="Waypoint6" x="437" y="337"/>
  <object name="Waypoint7" x="888" y="339"/>
 </objectgroup>

遍历多个对象:

auto *objects = this->tileMap->objectGroupNamed("Objects");
std::string stringWithFormat = "Waypoint";
int wayPointCounter = 0;
ValueMap wayPoint;
wayPoint = objects->objectNamed(stringWithFormat + std::to_string(wayPointCounter));
while (wayPoint.begin()!= wayPoint.end())
	{
		int x = wayPoint.at("x").asInt();
		int y = wayPoint.at("y").asInt();
		wayPointCounter++;
		wayPoint = objects->objectNamed(stringWithFormat + std::to_string(wayPointCounter));
	}

获取GID键值:

int tileGid = this->background->getTileGIDAt(point);
Value props = this->tileMap->getPropertiesForGID(tileGid);
ValueMap map = props.asValueMap();
int type_int;
type_int = map.at("buildable").asInt();


其实和2.x没什么区别,因为3.x中用value代替了array,所以遍历上会有稍微的不同

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值