TiledMAp 2.x 与 3.x 获取图层节点

TiledMAp  2.x  与  3.x  获取图层节点

2.x ***************************************************
TMXOrthoTest3::TMXOrthoTest3()
{
    CCTMXTiledMap *map = CCTMXTiledMap::create("TileMaps/orthogonal-test3.tmx");
    addChild(map, 0, kTagTileMap);
   
    CCSize CC_UNUSED s = map->getContentSize();
    CCLOG("ContentSize: %f, %f", s.width,s.height);
   
    CCArray* pChildrenArray = map->getChildren();//返回所有图层的节点
    CCSpriteBatchNode* child = NULL;
    CCObject* pObject = NULL;
    CCARRAY_FOREACH(pChildrenArray, pObject)//遍历节点放到  pObject
    {
        child = (CCSpriteBatchNode*)pObject;//强制转换为 CCSpriteBatchNode 类型

        if(!child)
            break;

        child->getTexture()->setAntiAliasTexParameters();//获取图层纹理设置抗锯龊
    }
   
    map->setScale(0.2f);
    map->setAnchorPoint( ccp(0.5f, 0.5f) );
}


3.x  **********************************************************
TMXOrthoTest3::TMXOrthoTest3()
{
    auto map = TMXTiledMap::create("TileMaps/orthogonal-test3.tmx");
    addChild(map, 0, kTagTileMap);
   
    Size CC_UNUSED s = map->getContentSize();
    CCLOG("ContentSize: %f, %f", s.width,s.height);
   
    auto& children = map->getChildren();//返回所有图层的节点
    SpriteBatchNode* child = nullptr;
//遍历节点放到  node
    for(const auto &node : children) {
        child = static_cast<SpriteBatchNode*>(node);
        child->getTexture()->setAntiAliasTexParameters();//获取图层纹理设置抗锯龊
    }
   
    map->setScale(0.2f);
    map->setAnchorPoint( Vec2(0.5f, 0.5f) );
}


你可能感兴趣的:(获取图层节点)