加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 19:51:37 所属栏目:百科 来源:网络整理
导读:Director :: getInstance ()- getVisibleSize (); auto tg = TMXTiledMap :: create ( "game.tmx" ); //加载地图文件 this - addChild (tg); auto monster = tg- getObjectGroup ( "monster" ); //获取地图对象层 int height = 0 ; auto vcObjects = monster

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 显示打印信息

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读