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


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

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


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

示例1: startPlay

//private
void RPGMapSceneLayer::startPlay(float delay)
{
    CCTMXTiledMap *bgMap = (CCTMXTiledMap*)this->getChildByTag(kRPGMapSceneLayerTagBgMap);
    
    //数据库部分,读取npc数据
    CppSQLite3Query query = this->m_db.execQuery(CCString::createWithFormat(NPC_QUERY, this->m_mapData.mapId)->getCString());
    while(!query.eof())
    {
        float x = (stringToNumber<float>(query.getStringField("tmx_x")) + 0.5) * GAME_TMX_ROLE_WIDTH;
        float y = (stringToNumber<float>(query.getStringField("tmx_y")) + 0.5) * GAME_TMX_ROLE_HEIGHT;
        bool autoMove = query.getIntField("auto_move") == 1 ? true : false;
        
        RPGMapNPCRoleSprite *npc = RPGMapNPCRoleSprite::create(query.getIntField("id"), CCString::create(query.getStringField("map_texture")), CCString::create("head_texture"), CCString::create(query.getStringField("name_cns")), CCString::create(query.getStringField("content_cns")), 1, autoMove);
        npc->setTag(kRPGMapSceneLayerTagNPC + query.getIntField("id"));
        npc->setPosition(ccp(x, y));
        bgMap->addChild(npc);
        
        query.nextRow();
    }
    query.finalize();
    
    //player
    int defaultSpriteFrameIndex = 1; //默认为向下
    if(this->m_mapData.playerDirection.compare("up") == 0)
    {
        defaultSpriteFrameIndex = 10;
    }
    else if(this->m_mapData.playerDirection.compare("left") == 0)
    {
        defaultSpriteFrameIndex = 4;
    }
    else if(this->m_mapData.playerDirection.compare("right") == 0)
    {
        defaultSpriteFrameIndex = 7;
    }
    RPGMapRoleSprite *player = RPGMapRoleSprite::create(CCString::create("actor4_0.png"), CCString::create("Player"), true, defaultSpriteFrameIndex);
    player->setPosition(ccp(this->m_mapData.playerToX * GAME_TMX_ROLE_WIDTH, this->m_mapData.playerToY * GAME_TMX_ROLE_HEIGHT));
    player->setTag(kRPGMapSceneLayerTagPlayer);
    player->m_type = kRPGMapRoleSpriteTypePlayer;
    bgMap->addChild(player);
    
    CCSprite *spJoystick = CCSprite::createWithSpriteFrameName("Ball.png");
    CCSprite *joystickBg = CCSprite::createWithSpriteFrameName("Dock.png");
    OzgJoystickLayer *joystick = OzgJoystickLayer::layerActivityJoystick(50, spJoystick, joystickBg, false);
    joystick->setTag(kRPGMapSceneLayerTagJoystick);
    joystick->m_target = this;
    joystick->m_endedSelector = callfunc_selector(RPGMapSceneLayer::joystickEndedFunc);
    this->addChild(joystick);
    
    //menu
    CCMenu *mainMenu = CCMenu::create();
    mainMenu->setTag(kRPGMapSceneLayerTagMainMenu);
    mainMenu->setAnchorPoint(ccp(0.5, 0.5));
    mainMenu->setPosition(CCPointZero);
    mainMenu->setContentSize(bgMap->getContentSize());
    bgMap->addChild(mainMenu);

    CCMenuItemSprite *menuCommand = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), this, menu_selector(RPGMapSceneLayer::onMenu));
    menuCommand->setPosition(ccp(mainMenu->getContentSize().width - 35, mainMenu->getContentSize().height - 35));
    menuCommand->setTag(kRPGMapSceneLayerTagMainMenuCommand);
    menuCommand->setRotation(180);
    menuCommand->setScale(0.75);
    mainMenu->addChild(menuCommand);

//    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
    CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 1, true);
    this->scheduleUpdate();
    
}
开发者ID:ChinaiOS,项目名称:OzgGameRPG,代码行数:70,代码来源:RPGMapSceneLayer.cpp

示例2: init

bool LevelScenePopUp::init()
{
    /*if ( !CCLayer::init() )
    {
        return false;
    }*/
    Level* current_level = _parent->getLevel();
    //Get the size of the screen we can see
    CCSize visibleSize = ADScreen::getVisibleSize();
    //Get the screen start of cordinates
    CCPoint origin = ADScreen::getOrigin();
    float scaled = ADScreen::getScaleFactor();

    //Create the sheet
    //_sheet_menu = CCNode::create();
    //this->addChild(_sheet_menu);
    _sheet_menu = this;
    SpritesLoader spl = GraphicsManager::getLoaderFor(_sheet_menu,
                                                      "level/level_end_menu.plist",
                                                      "level/level_end_menu.png");
    spl->inject(true);
    CCSprite* sheet = spl->loadSprite("sheet-horizontal.png");
    //const unsigned int ELEMENTS_LAYER=100;
    //sheet->setVisible(false);

    //Create the zone for menu
    float banner_padding = 15/scaled;
    float zone_margin = 0;

    CCSize menu_zone_size(sheet->getContentSize());
    float free_space = (visibleSize.height - menu_zone_size.height*1.1)/2;
    float max_space = free_space * 1.8;
    float move_up = 0;
    CCSize banner_size(visibleSize.width*0.9, max_space - banner_padding);

//    _pause_banner = ads::AdsManager::getInstance().getBanner(banner_size);
//    if(_pause_banner)
//    {
//        _parent->getParentScene()->addChild(_pause_banner);
//        _pause_banner->setAnchorPoint(ccp(0.5,0));
//        _pause_banner->setPosition(origin.x + visibleSize.width/2,
//                                   origin.y + banner_padding);
//        //_pause_banner->showAds();

//        float banner_height = _pause_banner->getContentSize().height + banner_padding;
//        if(banner_height > free_space)
//            move_up = banner_height - free_space;
//        zone_margin = move_up;
//    }


    _sheet_target_position = ccp(visibleSize.width/2+origin.x,
                                (visibleSize.height-zone_margin)/2+zone_margin+origin.y);
    _sheet_menu->setPosition(ccp(_sheet_target_position.x,
                                 _sheet_target_position.y-visibleSize.height));
    _sheet_menu->setContentSize(menu_zone_size);
    _sheet_menu->setAnchorPoint(ccp(0.5,0.5));
    _sheet_menu->runAction(CCMoveTo::create(0.2f, _sheet_target_position));

    //sheet->setRotation(-90);
    sheet->setAnchorPoint(ccp(0,0));
    //sheet->removeFromParent();

    //Place buttons
    CCMenu* menu = CCMenu::create();
    menu->setPosition(sheet->getPosition());
    menu->setAnchorPoint(ccp(0,0));
    menu->setContentSize(menu_zone_size);
    _sheet_menu->addChild(menu);

    //CCSprite* next_level_image = CCSprite::create("level/next_level.png");
    CCSprite* next_level_image = CCSprite::create("level/next_level_background.png");

    CCSize image_size = next_level_image->getContentSize();
    float design_scale = 1;

    ADMenuItem *first_button = 0;
    if(current_level->getLevelState() == Level::Crown)
    {
        //CCSprite* levels = CCSprite::create("level/levels.png");
        CCSprite* levels = CCSprite::create("level/levels_background.png");
        first_button = ADMenuItem::create(levels);
        CONNECT(first_button->signalOnClick,
                this, &LevelScenePopUp::onLevels);
    }
    else
    {
        //CCSprite* find_more_image = CCSprite::create("level/find_more.png");
        CCSprite* find_more_image = CCSprite::create("level/find_more_background.png");
        first_button = ADMenuItem::create(find_more_image);
        CONNECT(first_button->signalOnClick,
                this, &LevelScenePopUp::onFindMoreSolutions);
    }
    //TODO: change if it is necessary x coordinate to 102
    first_button->setPosition(ccp(100*design_scale/scaled+image_size.width/2,
                                  53*design_scale/scaled+image_size.height/2));

    ADMenuItem *next_level = ADMenuItem::create(next_level_image);
    CONNECT(next_level->signalOnClick,
            this, &LevelScenePopUp::onNextLevel);
//.........这里部分代码省略.........
开发者ID:seagullua,项目名称:MathIsFun2,代码行数:101,代码来源:LevelScenePopUp.cpp

示例3: initBottomBar

// 初始化底部Bar
void ActivityView::initBottomBar(CCSize winSize) 
{
	/////////////////////////////////////////// 底部条 ////////////////////////////////////////
	
	this->footerBarNode = CCNode::create() ;
	this->footerBarNode->setAnchorPoint(ccp(0, 0)) ;
	this->footerBarNode->setPosition(ccp(0, -5)) ;	
	this->addChild(this->footerBarNode) ;

	/////////////////////////////////////// 定义背景 /////////////////////////////////////////
	// 背景
	CCSprite* bottomBarBg = CCSprite::create("bg_bottom_bar.png") ;
	bottomBarBg->setAnchorPoint(ccp(0.5, 0)) ;
	bottomBarBg->setPosition(ccp(winSize.width/2, 0)) ;
	this->footerBarNode->addChild(bottomBarBg, 1) ;

	// 定义底部条高度
	const float footerBarNode_height = bottomBarBg->getContentSize().height ;
	// 设置底部条的高和宽
	this->footerBarNode->setContentSize(CCSizeMake(winSize.width, footerBarNode_height)) ;

	// 背景遮罩层
	CCSprite* bottomBg = CCSprite::create("bg_bottom.png") ;
	bottomBg->setAnchorPoint(ccp(0, 1)) ;
	bottomBg->setPosition(ccp(0, footerBarNode_height)) ;
	this->footerBarNode->addChild(bottomBg, 0) ;


	CCSpriteBatchNode* bottomIcon = CCSpriteBatchNode::create("bg_bottom_icon.png") ;

	// 左边的icon
	CCSprite* leftIcon = CCSprite::createWithTexture(bottomIcon->getTexture()) ;
	leftIcon->setAnchorPoint(ccp(0, 0)) ;
	leftIcon->setPosition(ccp(0, 0)) ;
	this->footerBarNode->addChild(leftIcon, 1) ;

	// 右边的icon
	CCSprite* rightIcon = CCSprite::createWithTexture(bottomIcon->getTexture()) ;
	rightIcon->setAnchorPoint(ccp(1, 0)) ;
	rightIcon->setPosition(ccp(winSize.width, 0)) ;
	rightIcon->setFlipX(true) ; // 水平翻转
	this->footerBarNode->addChild(rightIcon, 1) ;

	const float menuItem_margin = 50.0f ;		// 距离中间位置的距离
	const float menuItem_padding = 100.0f ;		// menuItem之间的间隔

	// 底部菜单
	CCMenu* footerMenu = CCMenu::create() ;
	footerMenu->setContentSize(CCSizeMake(winSize.width, footerBarNode_height) ) ;
	footerMenu->setAnchorPoint(ccp(0, 0)) ;
	footerMenu->setPosition(ccp(0, 0)) ;
	this->footerBarNode->addChild(footerMenu, 2) ;

	// 活动菜单
	CCMenuItemImage* activityMenuItem = CCMenuItemImage::create("menu_activity_n.png", "menu_activity_s.png", 
																this, menu_selector(ActivityView::menuActivityClickCallback)) ;
	activityMenuItem->setAnchorPoint(ccp(1, 1)) ;
	activityMenuItem->setPosition(ccp(winSize.width/2-menuItem_margin, footerBarNode_height-3)) ;
	footerMenu->addChild(activityMenuItem) ;

	// 获取menuItem宽度
	const float menuItem_width = activityMenuItem->getContentSize().width ;


	// 信息菜单	
	CCMenuItemImage* infoMenuItem = CCMenuItemImage::create("menu_message_n.png", "menu_message_s.png", 
															this, menu_selector(ActivityView::menuInfoClickCallback)) ;
	infoMenuItem->setAnchorPoint(ccp(1, 1)) ;
	infoMenuItem->setPosition(ccp(winSize.width/2-menuItem_margin-menuItem_width-menuItem_padding, footerBarNode_height-3)) ;
	footerMenu->addChild(infoMenuItem) ;

	// 商城菜单
	CCMenuItemImage* shopMenuItem = CCMenuItemImage::create("menu_shop_n.png", "menu_shop_s.png", 
															this, menu_selector(ActivityView::menuShopClickCallback)) ;
	shopMenuItem->setAnchorPoint(ccp(0, 1)) ;
	shopMenuItem->setPosition(ccp(winSize.width/2+menuItem_margin, footerBarNode_height-3)) ;
	footerMenu->addChild(shopMenuItem) ;

	// 菜单菜单
	CCMenuItemImage* moreMenuItem = CCMenuItemImage::create("menu_more_n.png", "menu_more_s.png" , 
															this, menu_selector(ActivityView::menuMoreClickCallback)) ;
	moreMenuItem->setAnchorPoint(ccp(0, 1)) ;
	moreMenuItem->setPosition(ccp(winSize.width/2+menuItem_margin+menuItem_width+menuItem_padding, footerBarNode_height-3)) ;
	footerMenu->addChild(moreMenuItem) ;
	
	// 更多菜单背景
	CCSprite* moreMenuBg = CCSprite::create("bg_more_menu.png") ;
	moreMenuBg->setAnchorPoint(ccp(0,0)) ;
	moreMenuBg->setPosition(ccp(0, 0)) ;

	const float moreMenu_width = moreMenuBg->getContentSize().width ;
	const float moreMenu_height = moreMenuBg->getContentSize().height ;

	// 更多菜单节点
	moreMenuNode = CCNode::create() ;
	moreMenuNode->setContentSize(moreMenuBg->getContentSize()) ;		// 设置moreMenuNode的尺寸
	moreMenuNode->setAnchorPoint(ccp(1, 0)) ;
	moreMenuNode->setPosition(ccp(winSize.width-80, 80)) ;
	moreMenuNode->retain() ;
//.........这里部分代码省略.........
开发者ID:fengmm521,项目名称:qipaiproject,代码行数:101,代码来源:ActivityView.cpp

示例4: onCreate

void BuyFullVersion::onCreate(CCNode *parent)
{
    float scaled = ADScreen::getScaleFactor();
    CCSize size = parent->getContentSize();
    float x_middle = size.width / 2;

    std::string title;
    std::string description_text;
    std::string buy_now_text;
    std::string buy_later_text;

    if(GameInfo::PURCHASE_TYPE == PurchaseType::AdsPurchaseFullVersion)
    {
        title = _("buy_full_version.title");
        description_text = _("buy_full_version.description");
        buy_now_text = _("pop_up.buy_full_version.button.buy_now");
        buy_later_text = _("pop_up.buy_full_version.button.later");
    }
    else
    {
        title = _("buy_no_ads.title");
        description_text = _("buy_no_ads.description");
        buy_now_text = _("pop_up.buy_no_ads.button.buy_now");
        buy_later_text = _("pop_up.buy_no_ads.button.later");
    }

    //create window title
    CCLabelTTF* window_title = CCLabelTTF::create(title.c_str(),
                                                  ADLanguage::getFontName(),
                                                  45);
    window_title->setColor(GameInfo::COLOR_LIGHT_BLUE);
    window_title->setPosition(ccp(x_middle, size.height * 0.85f));
    parent->addChild(window_title);

    /////////////////////////////////////////////////////////

    //add full version description
    CCLabelTTF* description = CCLabelTTF::create(description_text.c_str(),
                                                  ADLanguage::getFontName(),
                                                  32,
                                                 CCSize(parent->getContentSize().width* 0.6f, 0),
                                                 kCCTextAlignmentLeft);

    description->setColor(GameInfo::COLOR_LIGHT_GRAY);
    description->setPosition(ccp(x_middle+size.width*0.17, size.height * 0.55f));
    parent->addChild(description);

    ////////////////////////////////////////////////////

    //create menu for buttons
    CCMenu* menu = CCMenu::create();
    menu->setPosition(ccp(0,0));
    menu->setAnchorPoint(ccp(0,0));
    menu->setContentSize(size);
    parent->addChild(menu);

    //create zebra image
    CCSprite* zebra = CCSprite::create("select_collection/zebra.png");
    parent->addChild(zebra);
    zebra->setScale(0.9f);
    zebra->setPosition(ccp(200/scaled, 280/scaled));


    CCSprite* button1 = CCSprite::create("select_collection/background1.png");

    //////////////////////////////////////////////////

    //buy now
    CCSprite* button2 = CCSprite::create("select_collection/background1.png");
    CCLabelTTF* buy_now_title = CCLabelTTF::create(buy_now_text.c_str(),
                                                   ADLanguage::getFontName(),
                                                   45);
    buy_now_title->setColor(GameInfo::COLOR_DARK_GREEN);

    float BUTTON_WIDTH_USED = 0.85f;

    //fix font size
    if(buy_now_title->getContentSize().width >= button2->getContentSize().width*BUTTON_WIDTH_USED)
    {
        buy_now_title->setScale(button2->getContentSize().width*BUTTON_WIDTH_USED
                                / buy_now_title->getContentSize().width);
    }
    if(buy_now_title->getContentSize().height >= button2->getContentSize().height*BUTTON_WIDTH_USED)
    {
        float scale = button2->getContentSize().height*BUTTON_WIDTH_USED
                / buy_now_title->getContentSize().height;
        if(scale < buy_now_title->getScale())
        {
            buy_now_title->setScale(scale);
        }
    }

    button2->setColor(GameInfo::COLOR_DARK_GREEN);
    ADMenuItem *buy_now_item = ADMenuItem::create(button2);
    buy_now_item->addChild(buy_now_title);
    CONNECT(buy_now_item->signalOnClick,
            this, &BuyFullVersion::onBuyFullVersionClick);


    buy_now_title->setPosition(buy_now_item->getContentSize()*0.5);
//.........这里部分代码省略.........
开发者ID:seagullua,项目名称:MathIsFun2,代码行数:101,代码来源:BuyFullVersion.cpp

示例5: initTopBar

// 初始化顶部bar
void ActivityView::initTopBar(CCSize winSize) 
{
	////////////////////////////////////////////////////////////////////////////////////////////////////
	// topBarNode 背景
	CCSprite* topBarBg = CCSprite::create("bg_nav_top.png") ;
	topBarBg->setAnchorPoint(ccp(0.5, 0)) ;
	topBarBg->setPosition(ccp(winSize.width/2, 0)) ;

	const float topBar_height = topBarBg->getContentSize().height ; 

	

	// 顶部条信息 //////////////////////////////////////////////////////////////////////////////////////
	this->topBarNode = CCNode::create() ;
	this->topBarNode->setContentSize(CCSizeMake(winSize.width, topBar_height)) ;
	this->topBarNode->setAnchorPoint(ccp(0, 0)) ;
	this->topBarNode->setPosition(ccp(0, winSize.height - topBar_height)) ;
	this->addChild(this->topBarNode, 0, 1) ;

	// 将topBarNode背景加入到topBarNode
	this->topBarNode->addChild(topBarBg, 0 ) ;


	///////////////////////////// 左侧布局 //////////////////////////
	CCNode* leftNode = CCNode::create() ;
	leftNode->setContentSize(CCSizeMake(300, topBar_height)) ;
	leftNode->setAnchorPoint(ccp(0, 0.5)) ;
	leftNode->setPosition(ccp(30, topBar_height/2)) ;
	this->topBarNode->addChild(leftNode, 1) ;

	// 头像
	CCSprite* headPortraitSprite = CCSprite::create("user/head_default_f2.png") ;
	headPortraitSprite->setAnchorPoint(ccp(0, 0)) ;
	headPortraitSprite->setPosition(ccp(0, 10)) ;
	headPortraitSprite->setScale(0.8) ;
	leftNode->addChild(headPortraitSprite) ;

	// 昵称
	CCLabelTTF* nikeNameLabel = CCLabelTTF::create("昵称:我是主角", "font01.ttf", 22.0f) ;
	// nikeNameLabel->setColor(ccc3(191, 173, 111)) ;
	nikeNameLabel->setAnchorPoint(ccp(0, 0)) ;
	nikeNameLabel->setPosition(ccp(70, topBar_height/2+2)) ;
	nikeNameLabel->setHorizontalAlignment(kCCTextAlignmentLeft) ; 			// 水平对齐方式
	nikeNameLabel->setVerticalAlignment(kCCVerticalTextAlignmentCenter) ; 	// 垂直对齐方式
	leftNode->addChild(nikeNameLabel) ;

	// 金币
	CCLabelTTF* goldCoinLabel = CCLabelTTF::create("金币:10000", "font01.ttf", 22.0f) ;
	goldCoinLabel->setAnchorPoint(ccp(0, 1)) ;
	goldCoinLabel->setPosition(ccp(70, topBar_height/2)) ;
	goldCoinLabel->setHorizontalAlignment(kCCTextAlignmentLeft) ; 			// 水平对齐方式
	goldCoinLabel->setVerticalAlignment(kCCVerticalTextAlignmentCenter) ; 	// 垂直对齐方式
	leftNode->addChild(goldCoinLabel) ;


	// 信息
	CCSprite* titleMsg = CCSprite::create("icon_title_activity.png") ;
	titleMsg->setAnchorPoint(ccp(0.5, 0.5)) ;
	titleMsg->setPosition(ccp(winSize.width/2, topBar_height/2)) ;
	this->topBarNode->addChild(titleMsg, 1) ;

	// 分割线
	CCSprite* spliteLineLeft = CCSprite::create("icon_top_nav_splite.png") ;
	spliteLineLeft->setAnchorPoint(ccp(0, 1)) ;
	spliteLineLeft->setPosition(ccp(winSize.width/3+10, topBar_height)) ;
	this->topBarNode->addChild(spliteLineLeft, 1) ;


	// 分割线
	CCSprite* spliteLineRight = CCSprite::create("icon_top_nav_splite.png") ;
	spliteLineRight->setAnchorPoint(ccp(0, 1)) ;
	spliteLineRight->setPosition(ccp(winSize.width*2/3-20, topBar_height)) ;
	this->topBarNode->addChild(spliteLineRight, 1) ;


	/////////////////////////////////////////////////////////////////////////////////////////////////
	/****************************** 菜单选项 ********************************************************/
	// 右侧menu
	const float right_width = 200 ;
	const float item_width = 55 ;

	
	// 礼物
	CCMenuItemImage* menuGifts = CCMenuItemImage::create("menu_gifts_n.png", "menu_gifts_s.png", this,
															menu_selector(ActivityView::menuGiftsClickCallback)) ;
	// menuBack->setContentSize(CCSizeMake(67, 68)) ;
	menuGifts->setAnchorPoint(ccp(0, 0.5)) ;
	menuGifts->setPosition(ccp(0, topBar_height/2)) ;
	//menuGifts->setPosition(ccp(right_width-2*item_width, topBar_height/2)) ;
	//rightMenu->addChild(menuGifts) ;

	// 返回大厅
	CCMenuItemImage* menuBack = CCMenuItemImage::create("menu_back_n.png", "menu_back_s.png", this,
															menu_selector(MessageView::menuBackClickCallback)) ;
	menuBack->setAnchorPoint(ccp(0, 0.5)) ;
	menuBack->setPosition(ccp(2*(item_width+10), topBar_height/2)) ;
	//menuBack->setPosition(ccp(right_width, topBar_height/2)) ;
	//rightMenu->addChild(menuBack) ;

//.........这里部分代码省略.........
开发者ID:fengmm521,项目名称:qipaiproject,代码行数:101,代码来源:ActivityView.cpp


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