Cocos2d-x_地图(背景)介绍

前端之家收集整理的这篇文章主要介绍了Cocos2d-x_地图(背景)介绍前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
// 图层
bool HelloWorld::init()
{
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    
    CCTMXTiledMap *map = CCTMXTiledMap::create("map1.tmx");
    this->addChild(map);
    
    CCSize mapSize = map->getMapSize();
    CCSize tilesSize = map->getTileSize();
    
    CCLOG("mapSize:%f_%f,tilesSize:%f_%f",mapSize.width,mapSize.height,tilesSize.width,tilesSize.height);
    
    CCArray *pChildArray = map->getChildren();
    CCSpriteBatchNode *child = NULL;
    CCObject *pObject = NULL;
    
    // 遍历每个图块,并且设置抗锯齿
    CCARRAY_FOREACH(pChildArray,pObject)
    {
        child = (CCSpriteBatchNode *)pObject;
        
        if (!child)
        {
            break;
        }
        else
        {
            child->getTexture()->setAntiAliasTexParameters();
        }
    }
    
    // 取出图层中的最后一个图块进行操作
    CCTMXLayer *layer = map->layerNamed("layer1");
    CCSprite *pSpr = layer->tileAt(ccp(9,9));
    pSpr->setScale(1);
    pSpr->setRotation(-90);
    
    return true;
}

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