Director::getInstance()->getVisibleSize();
auto tg = TMXTiledMap::create("game.tmx"); //加载地图文件
this->addChild(tg);
auto monster = tg->getObjectGroup("monster"); //获取地图对象层
int height = 0;
auto vcObjects = monster->getObjects(); // 获取对象层中所有的对象
for (auto v : vcObjects) {
const ValueMap dict = v.asValueMap();
int id = dict.at("id").asInt();
float fShwoTime = dict.at("showTime").asFloat();
int posX = dict.at("x").asInt();
int posY = dict.at("y").asInt();
auto msg = String::createWithFormat("X = %d,y= %d,id = %d,showTime = %f",posX,posY,id,fShwoTime);
auto lbel = Label::create(msg->getCString(),"Arial",24);
auto size = lbel->getContentSize();
lbel->setPosition(Vec2(visibleSize.width /2,visibleSize.height - size.height / 2 - height));
height += size.height;
this->addChild(lbel); // label 显示打印信息
}
原文链接:https://www.f2er.com/cocos2dx/345370.html