本文整理汇总了C++中TMXTiledMap::getProperty方法的典型用法代码示例。如果您正苦于以下问题:C++ TMXTiledMap::getProperty方法的具体用法?C++ TMXTiledMap::getProperty怎么用?C++ TMXTiledMap::getProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TMXTiledMap
的用法示例。
在下文中一共展示了TMXTiledMap::getProperty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadMap
bool GameMap::loadMap(const int& level)
{
string fileName = StringUtils::format("map/map_%03d.tmx", level);
TMXTiledMap* map = TMXTiledMap::create(fileName);
m_map = map;
float scale = 1 / Director::getInstance()->getContentScaleFactor();
//GridPos
TMXObjectGroup* group = map->getObjectGroup("TowerPos");
ValueVector vec = group->getObjects();
m_gridPos.clear();
m_gridPos.resize(vec.size());
if (!vec.empty())
{
int i = 0;
for (const auto& v : vec)
{
const ValueMap& dict = v.asValueMap();
m_gridPos[i] = new GridPos(
i,
Rect(dict.at("x").asFloat(),
dict.at("y").asFloat(),
dict.at("width").asFloat(),
dict.at("height").asFloat()));
i++;
}
}
//计算临近的塔的ID
float h = group->getProperty("TowerPosHeight").asFloat() *scale;
float w = group->getProperty("TowerPosWidth").asFloat() *scale;
float dis = (h + 2)*(h + 2) + (w + 2)*(w + 2);
vector<int> GridPosID;
for (auto t1 : m_gridPos)
{
GridPosID.clear();
Point pos = t1->getPos();
for (auto t2 : m_gridPos)
{
if (t1 != t2 && pos.distanceSquared(t2->getPos())<=dis)
{
GridPosID.push_back(t2->ID);
}
}
int around[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
for (auto tid : GridPosID)
{
Rect rect = m_gridPos[tid]->getRect();
if (rect.containsPoint( Point(pos.x , pos.y + h )))around[North] = tid;
else if (rect.containsPoint( Point(pos.x - w, pos.y + h )))around[NorthWest] = tid;
else if (rect.containsPoint( Point(pos.x - w, pos.y )))around[West] = tid;
else if (rect.containsPoint( Point(pos.x - w, pos.y - h )))around[SouthWest] = tid;
else if (rect.containsPoint( Point(pos.x , pos.y - h )))around[South] = tid;
else if (rect.containsPoint( Point(pos.x + w, pos.y - h )))around[SouthEast] = tid;
else if (rect.containsPoint( Point(pos.x + w, pos.y )))around[East] = tid;
else if (rect.containsPoint( Point(pos.x + w, pos.y + h )))around[NorthEast] = tid;
}
t1->setAroundGridPosID(around);
}
//MonsterPath
group = map->getObjectGroup("Path");
vec = group->getObjects();
MonsterPath.clear();
if (!vec.empty())
{
vector<Point> posvec;
for (const auto& var : vec)
{
posvec.clear();
const ValueMap& dict = var.asValueMap();
const ValueVector& vec2 = dict.at("polylinePoints").asValueVector();
Point pos = Point(dict.at("x").asFloat(), dict.at("y").asFloat());
for (const auto& v : vec2)
{
const ValueMap& dict = v.asValueMap();
posvec.push_back(Point(pos.x + dict.at("x").asFloat()*scale, pos.y - dict.at("y").asFloat()*scale));
//posvec.push_back(Point(pos.x + dict.at("x").asFloat(), pos.y - dict.at("y").asFloat()));
}
MonsterPath.push_back(MapPath(dict.at("LoopTo").asInt(), posvec));
}
}
//WaveData
int waveCount= map->getProperty("WaveCount").asInt();
std::stringstream ss;
string propertyName;
WaveList.clear();
for (int i = 1; i <= waveCount; i++)
{
propertyName = StringUtils::format("Wave%03d", i);
group = map->getObjectGroup(propertyName);
CCASSERT(group != nullptr, string("propertyName :" + propertyName +" NOT found").c_str());
Wave wave;
wave.WaveTime = group->getProperty("waveTime").asInt();
//.........这里部分代码省略.........