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

    }


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章