当前位置: 首页>>代码示例>>C++>>正文


C++ CCMenuItem::setContentSize方法代码示例

本文整理汇总了C++中CCMenuItem::setContentSize方法的典型用法代码示例。如果您正苦于以下问题:C++ CCMenuItem::setContentSize方法的具体用法?C++ CCMenuItem::setContentSize怎么用?C++ CCMenuItem::setContentSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CCMenuItem的用法示例。


在下文中一共展示了CCMenuItem::setContentSize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: initTopMenu

bool CCLobbyView::initTopMenu()
{
    CCDirector* director = CCDirector::sharedDirector();
    const CCSize winSize = director->getWinSize();
    const CCSize mySize = this->getContentSize();
    const CCPoint center = ccpMult( ccpFromSize( mySize ), 0.5f );
    
    CCLabelTTF* consoleLabel = CCLabelTTF::create( "disconnected", "Arial", FONT_SIZE(24), CCSizeMake( winSize.width, FONT_SIZE(24) ), kCCTextAlignmentCenter );
    consoleLabel->setColor( ccc3(255, 255, 255) );
    CCMenuItemLabel* consoleItem = CCMenuItemLabel::create( consoleLabel );
    
    // bottom
    const CCSize editSize = CCSizeMake( winSize.width, FONT_SIZE(48) );
    CCMenuItem* editItem = CCMenuItem::create();
    editItem->setContentSize( editSize );
    
    CCMenu* topMenu = CCMenu::create( consoleItem, editItem, NULL );
    if( topMenu )
    {
        this->setConsole( consoleLabel );
        
        topMenu->alignItemsVertically();
        topMenu->setPosition( CCPointMake( center.x, winSize.height - (editItem->getContentSize().height + consoleItem->getContentSize().height)/2 ) );
        this->addChild( topMenu, 0, Child::CCMenu_topMenu );
        
        const CCPoint editItemPosition = editItem->getParent()->convertToWorldSpace( editItem->getPosition() );
        editItem->setContentSize( winSize );
        editItem->ignoreAnchorPointForPosition( false );
        editItem->setAnchorPoint( ccp( 0.5f, (winSize.height / (editItemPosition.y - winSize.height)) * 0.5f ) );
        
        CCScale9Sprite* editSprite = CCScale9Sprite::create("extensions/yellow_edit.png");
        CCEditBox* edit = CCEditBox::create( editSize, editSprite );
        edit->setPlaceHolder("PlayerName");
        edit->setReturnType(kKeyboardReturnTypeDone);
        edit->setFontColor(ccGRAY);
        edit->setMaxLength( 20 );
        edit->setDelegate(this);
        edit->setTouchEnabled( true );
        edit->setPosition( editItemPosition );
        CocosNetworkLogic* network = CocosNetworkLogic::getInstance();
        JString userName = network->getUserName();
        edit->setText(userName.UTF8Representation().cstr());
        this->addChild( edit );
        this->setEditName(edit);
    }
    
    return topMenu;
}
开发者ID:kaznog,项目名称:t09,代码行数:48,代码来源:CCLobbyView.cpp

示例2: fillBanner

void ADAds::fillBanner(Banner* banner)
{
#if defined(_DEBUG) && CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
    CCRenderTexture* texture = CCRenderTexture::create(100, 100);
    texture->beginWithClear(0.5f, 0.5f, 0.5f, 1);

    texture->end();

    CCSprite* s = CCSprite::createWithTexture(texture->getSprite()->getTexture());

    s->setScaleX(banner->getContentSize().width/s->getContentSize().width);
    s->setScaleY(banner->getContentSize().height/s->getContentSize().width);
    banner->addChild(s);
    s->setAnchorPoint(ccp(0,0));
    s->setPosition(ccp(0,0));
#endif

    if(_home_banners.size())
    {
        //std::random_shuffle(_home_banners.begin(), _home_banners.end());
        CustomBanner* home_ads = getCustomBanner();

        CCMenuItem* item = CCMenuItem::create(
                               home_ads, menu_selector(CustomBanner::onClick));


        CCMenu* menu = CCMenu::create();
        menu->addChild(item);

        banner->addChild(menu, 0, HOME_ADS_NODE_TAG);
        menu->setAnchorPoint(ccp(0,0));

        menu->setPosition(ccp(0,0));

        CCNode* banner_content = home_ads->getBanner();
        CCSize content_size = banner_content->getContentSize();
        CCSize zone_size = banner->getContentSize();

        float scale = MIN(zone_size.width/content_size.width,
                          zone_size.height/content_size.height);
        banner_content->setScale(scale);
        banner_content->setAnchorPoint(ccp(0, 0));
        banner_content->setPosition(ccp(0,0));

        item->setContentSize(content_size*scale);
        item->setAnchorPoint(ccp(0.5f,0.5f));
        item->setPosition(zone_size*0.5f);
        item->addChild(banner_content);
    }
}
开发者ID:4Enjoy,项目名称:ADLib,代码行数:50,代码来源:ADAds.cpp

示例3: initPassAndPlay

bool MainMenu::initPassAndPlay()
{
    this->removeChildByTag( Child::CCMenuItem_passAndPlay, true );
    
    CCMenuItem* item = CCMenuItem::create( this, menu_selector( MainMenu::passAndPlayCallback ) );
    CCSprite* sprite = CCSprite::create( "button_passAndPlay.png" );
    sprite->setAnchorPoint(CCPointZero);
    item->setContentSize( sprite->getContentSize() );
    item->addChild( sprite );
    CCLabelTTF* label = CCLabelTTF::create("Pass and Play", "American Typewritter.ttf", 24);
    label->setAnchorPoint(CCPointZero);
    label->setPosition( ccp( sprite->getContentSize().width * 0.25, sprite->getContentSize().height * 0.5 ) );
    item->addChild(label);
    
    this->addChild( item, 0, Child::CCMenuItem_passAndPlay );
    return true;
}
开发者ID:georgemguy,项目名称:Cocos2d-x_Photon_MultiPlatform_Test,代码行数:17,代码来源:MainMenu.cpp

示例4: init

// on "init" you need to initialize your instance
bool TableBar::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    //每个项目都要创建的东西
    _menu = CCMenu::create(NULL);
    _menu->setPosition(CCPointZero);
    this->addChild(_menu, zNum+1);
    
    pTabBar = CCSprite::create("pTabBar.png");
    pTabBar->setPosition(ccp(1024.0,49.0));    
    this->addChild(pTabBar,zNum);

    
    m_highlightSp = CCSprite::create("pTabBarSelectedHighlight.png");


    string plistStr = TableBar::classPlistName;
    plistStr += ".plist";
    plistDic = CCDictionary::createWithContentsOfFile(plistStr.c_str());
    
    for (int i = 0; i<itemVec.size(); i++)
    {
        const char * picNameStr =  (itemVec[i]+".png").c_str();
        CCSprite * aSprite = CCSprite::create(picNameStr);
        
        if (i == TableBar::mainItemNum)
        {
            mainitemSprite = aSprite;
        }
        
        const char * positionName = itemVec[i].c_str();
        aSprite->setPosition(ScriptParser::getPositionFromPlist(plistDic,positionName));        
        this->addChild(aSprite,zNum);
        
        CCMenuItem * aItem = CCMenuItem::create(this, menu_selector(TableBar::menuselect));
        aItem->setPosition(aSprite->getPosition());
        aItem->setContentSize(m_highlightSp->getContentSize());
        _menu ->addChild(aItem,zNum);
        aItem->setTag(i);
        
        const char * itemTitleStr = itemTitleVec[i].c_str();
        CCLabelTTF* pLabel = CCLabelTTF::create(itemTitleStr,fontName_macro,fontSize_macro);
        if (i == TableBar::mainItemNum)
        {
            pLabel->setColor(White_macro);
        }
        else
        {
            pLabel->setColor(gray_macro);
        }

        const char * labelNameStr =  (itemVec[i]+"Label").c_str();
        pLabel->setPosition(ScriptParser::getPositionFromPlist(plistDic,labelNameStr));
        this->addChild(pLabel, zNum);
    }

    m_highlightSp->setPosition(ccp(mainitemSprite->getPosition().x,pTabBar->getPosition().y+pTabBar->getContentSize().height/2-50));
    this->addChild(m_highlightSp,zNum);
    m_highlightSp->setColor(ccc3(200, 200, 200));
    
    return true;
}
开发者ID:liuyuyefz,项目名称:GreTest,代码行数:68,代码来源:TableBar.cpp


注:本文中的CCMenuItem::setContentSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。