cocos2dx3.2 加载地图和读取数据的简单使用

前端之家收集整理的这篇文章主要介绍了cocos2dx3.2 加载地图和读取数据的简单使用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

猜你在找的Cocos2d-x相关文章