this->_map = TMXTiledMap::create(tmxFile); this->_barriers = this->_map->getLayer("barriers"); this->_states->setVisible(false);//如果直接在editor中设置invisible,getLayer会返回nullptr // find auto layerSize = this->_states->getLayerSize(); auto tiles = this->_barriers->getTiles(); auto tilesEnd = tiles + static_cast<uint32_t>(layerSize.width * layerSize.height); for (; tiles < tilesEnd; ++tiles) { if (*tiles != 0) { auto properties = this->_map->getPropertiesForGID(*tiles).asValueMap(); if (!properties.empty()) { if (properties["property_name"].asString() == "1") { break; } } } //if }
这里还有些注意事项,
auto properties = this->_map->getPropertiesForGID(*tiles).asValueMap();这里不能用引用方式(auto &)