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


C++ CCMenu类代码示例

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


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

示例1: setKeypadEnabled

bool ChoosePackageScene::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }

    setKeypadEnabled(true);

    CCDirector *director = CCDirector::sharedDirector();
    LayoutManager *layoutManager = LayoutManager::getInstance();
    CCRect visibleRect = layoutManager->getVisibleRect();

    m_Background = CCSprite::create("bg_common.jpg");
    m_Background->retain();
    m_Background->setPosition(director->getVisibleOrigin() + director->getVisibleSize() / 2);
    addChild(m_Background);

    CCSprite *sprite = CCSprite::create("stage_select.png");
    sprite->setPosition(ccp(visibleRect.origin.x + visibleRect.size.width / 2, 630));
    addChild(sprite);

    // Create the page view
    int pageViewHeight = 556;
    int pageWidth = 336;
    LGPageView *pageView = LGPageView::create();
    pageView->setTouchEnabled(true);
    pageView->setSize(CCSizeMake(visibleRect.size.width, pageViewHeight));
    pageView->setPosition(CCSizeMake(visibleRect.origin.x,  + visibleRect.origin.y + (visibleRect.size.height - pageViewHeight) / 2));
    pageView->setPageWidth(pageWidth);
    pageView->setIndicatorEnable(true);

    StageManager *stageManager = StageManager::getInstance();
    for (int i = 0; i < sizeof(PACKAGE_IMAGE) / sizeof(PACKAGE_IMAGE[0]); ++i)
    {
        Layout *layout = Layout::create();
        layout->setSize(CCSizeMake(pageWidth, pageView->getSize().height));

        UIImageView *imageView = UIImageView::create();
        imageView->loadTexture(PACKAGE_IMAGE[i]);
        imageView->setPosition(ccp(layout->getRect().size.width / 2, layout->getRect().size.height / 2));
        imageView->setTag(i);
        imageView->addReleaseEvent(this, coco_releaseselector(ChoosePackageScene::selectPackageCallback));
        imageView->setTouchEnabled(true);
        layout->addChild(imageView);

        ccFontDefinition strokeTextDef;
        strokeTextDef.m_fontSize = 100;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
        strokeTextDef.m_fontName = "Lithograph";
#else
        strokeTextDef.m_fontName = "fonts/Lithograph.ttf";
#endif
        strokeTextDef.m_stroke.m_strokeEnabled = true;
        strokeTextDef.m_stroke.m_strokeColor = LayoutManager::getInstance()->DefaultStroke;
        strokeTextDef.m_stroke.m_strokeSize = 30;
        strokeTextDef.m_fontFillColor = ccWHITE;
        CCLabelTTF *labelStage = CCStrokeLabel::createWithFontDefinition(CCString::createWithFormat(" %d ", (i + 1))->getCString(), strokeTextDef);
        labelStage->setPosition(ccp(layout->getRect().size.width / 2, layout->getRect().size.height / 2));
        layout->addCCNode(labelStage);

        strokeTextDef.m_fontSize = 40;
        strokeTextDef.m_stroke.m_strokeSize = 16;
        CCLabelTTF *labelCompletion = CCStrokeLabel::createWithFontDefinition(CCString::createWithFormat(" %d/%d ", stageManager->getCompletedStageCount(i), stageManager->getStageCount(i))->getCString(), strokeTextDef);
        labelCompletion->setPosition(ccp(layout->getRect().size.width / 2, layout->getRect().size.height / 2 - labelStage->getContentSize().height / 2 - labelCompletion->getContentSize().height / 2));
        layout->addCCNode(labelCompletion);

        m_LabelCompletions->addObject(labelCompletion);

        pageView->addPage(layout);
    }

    UILayer *pUiLayer = UILayer::create();
    pUiLayer->addWidget(pageView);
    addChild(pUiLayer);
    pUiLayer->scheduleUpdate();

    CCMenuItemImage *pBack = CCMenuItemImage::create("back.png", NULL, this, menu_selector(ChoosePackageScene::backCallback));
    pBack->setAnchorPoint(CCPointZero);
    pBack->setPosition(ccp(visibleRect.origin.x + 18, visibleRect.origin.y + 12));

    CCMenu *pMenu = CCMenu::create(pBack, NULL);
    pMenu->setAnchorPoint(CCPointZero);
    pMenu->setPosition(CCPointZero);
    addChild(pMenu);

    return true;
}
开发者ID:studio501,项目名称:BlockPuzzle,代码行数:90,代码来源:ChoosePackageScene.cpp

示例2: menu_selector

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
    CCMenuItemImage *pCloseItem = CCMenuItemImage::itemWithNormalImage(
                                        "CloseNormal.png",
                                        "CloseSelected.png",
                                        this,
                                        menu_selector(HelloWorld::menuCloseCallback) );
    pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) );

    // create menu, it's an autorelease object
    CCMenu* pMenu = CCMenu::menuWithItems(pCloseItem, NULL);
    pMenu->setPosition( CCPointZero );
    this->addChild(pMenu, 1);

    /////////////////////////////
    // 3. add your codes below...

    // add a label shows "Hello World"
    // create and initialize a label
    CCLabelTTF* pLabel = CCLabelTTF::labelWithString("Hello World", "Thonburi", 34);

    // ask director the window size
    CCSize size = CCDirector::sharedDirector()->getWinSize();

    // position the label on the center of the screen
    pLabel->setPosition( ccp(size.width / 2, size.height - 20) );

    // add the label as a child to this layer
    this->addChild(pLabel, 1);

    // add "HelloWorld" splash screen"
    CCSprite* pSprite = CCSprite::spriteWithFile("HelloWorld.png");

    // position the sprite on the center of the screen
    pSprite->setPosition( ccp(size.width/2, size.height/2) );

    // add the sprite as a child to this layer
    this->addChild(pSprite, 0);
    
    AnalyticX::flurrySetAppVersion("v_1_97");
    cocos2d::CCLog("--->>>get flurry version = %s", AnalyticX::flurryGetFlurryAgentVersion());
    AnalyticX::flurrySetDebugLogEnabled(false);
    AnalyticX::flurrySetSessionContinueSeconds(143);
    AnalyticX::flurrySetSecureTransportEnabled(false);
    
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    AnalyticX::flurryStartSession("QFNXVFK2XX4P56GS76EA");
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    AnalyticX::flurryStartSession("W7IBK43RJCHPT4IRP4HI");
#endif
    
    AnalyticX::flurrySetUserID("fake_user_id");
    AnalyticX::flurrySetAge(34);
    AnalyticX::flurrySetGender("f");
    AnalyticX::flurrySetReportLocation(false);
    
    AnalyticX::flurryLogEvent("event_3");
    AnalyticX::flurryLogEventTimed(" log event timed test...", false);

    CCDictionary *testDict = new CCDictionary();

    CCString *testCCString;

    testCCString = CCString::stringWithCString("obj 0");

    testDict->setObject(testCCString, "key 0");

    testCCString = CCString::stringWithCString("obj 1");

    testDict->setObject(testCCString, "key 1");

    AnalyticX::flurryLogEventWithParameters("event_5_with_params_no_timed", testDict);

    AnalyticX::flurryLogEventWithParametersTimed("test flurryLogEventWithParameters + timed", testDict, true);
    AnalyticX::flurryEndTimedEventWithParameters("test end event...", NULL);
    
    AnalyticX::flurryLogPageView();
    
    //AnalyticX::flurryEndSession();
    return true;
}
开发者ID:FlowerpotGames,项目名称:AnalyticX,代码行数:95,代码来源:HelloWorldScene.cpp

示例3: CC_BREAK_IF

bool CGameMessage::init()
{
	bool bRet = false;
	do{
		CC_BREAK_IF(! CCLayer::init());

		CCSize size = CCDirector::sharedDirector()->getWinSize();
		CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Image/Message.plist");
		/**	信息框	*/
		CCSprite *pBox = CCSprite::createWithSpriteFrameName("Box.png");
		CC_BREAK_IF(! pBox);
		pBox->setPosition(ccp(size.width/2, size.height - pBox->getContentSize().height/2));
		this->addChild(pBox, 0);
		
		/**	分数	*/
		m_pScore = CCLabelAtlas::create("0", "Image/Num.plist");
		CC_BREAK_IF(! m_pScore);
		this->addChild(m_pScore, 0);
		m_pScore->setPosition(ccp(100, size.height - 24) );

		/**	生命	*/
		m_pLife = CCLabelAtlas::create("3", "Image/Num.plist");
		CC_BREAK_IF(! m_pLife);
		this->addChild(m_pLife, 0);
		m_pLife->setPosition(ccp(236, size.height - 20) );

		/**	HP	*/
		m_pHp = CCSprite::createWithSpriteFrameName("Hp.png");
		CC_BREAK_IF(! m_pHp);
		this->addChild(m_pHp, 0);
		m_pHp->setAnchorPoint(ccp(0, 0));
		m_iWidth = m_pHp->getContentSize().width;
		m_iHeight = m_pHp->getContentSize().height;
		m_pHp->setPosition(ccp(97, size.height - 49));
		m_fMinX = m_pHp->getTextureRect().getMinX();
		m_fMinY = m_pHp->getTextureRect().getMinY();

		// 导弹图标	
		m_pMissileItem = CCMenuItemImage::create();       
		CC_BREAK_IF(! m_pMissileItem);
		m_pMissileItem->setCallback( CC_CALLBACK_1( CGameMessage::shootMissile, this ) );
		m_pMissileItem->setNormalSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("MissileIco.png"));  
		m_pMissileItem->setSelectedSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("MissileIco.png"));
		m_pMissileItem->setPosition(ccp(15, 80));
		
		CCMenu *pMissile = CCMenu::create(m_pMissileItem, NULL);
		CC_BREAK_IF(! pMissile);
		pMissile->setPosition(ccp(0, 0));
		this->addChild(pMissile, 0);

		m_pMissileNum = CCLabelAtlas::create("2", "Image/Num.plist");
		CC_BREAK_IF(! m_pMissileNum);

		m_pMissileItem->addChild(m_pMissileNum, 0);
		this->scheduleUpdate();

		bRet = true;
	}
	while(0);

	return bRet;
}
开发者ID:Zerak,项目名称:LeiDian,代码行数:62,代码来源:GameMessage.cpp

示例4: CC_BREAK_IF

ControlLayer::ControlLayer( LayerSwitcher* pLayerSwitcher,MapControl* pControl )
{
	m_pLayerSwitcher = pLayerSwitcher;
	m_pControl = pControl;

	do 
	{
		//////////////////////////////////////////////////////////////////////////
		// super init first
		//////////////////////////////////////////////////////////////////////////

		CC_BREAK_IF(! CCLayer::init());

		//////////////////////////////////////////////////////////////////////////
		// add your codes below...
		//////////////////////////////////////////////////////////////////////////

		// 1. Add a menu item with "X" image, which is clicked to quit the program.

		// Create a "close" menu item with close icon, it's an auto release object.
		CCMenuItemImage *pZoomIn = CCMenuItemImage::create(
			"zoomin.png",
			"zoomin.png",
			this,
			menu_selector(ControlLayer::zoomIn));
		CC_BREAK_IF(! pZoomIn);

		// Place the menu item bottom-right conner.
		pZoomIn->setPosition(ccp(25, 25));

		// Create a menu with the "close" menu item, it's an auto release object.
		CCMenu* pMenu = CCMenu::create(pZoomIn, NULL);
		pMenu->setPosition(CCPointZero);
		CC_BREAK_IF(! pMenu);

		// Add the menu to HelloWorld layer as a child layer.
		this->addChild(pMenu, 1,1);

		// Create a "close" menu item with close icon, it's an auto release object.
		CCMenuItemImage *pZoomOut = CCMenuItemImage::create(
			"zoomout.png",
			"zoomout.png",
			this,
			menu_selector(ControlLayer::zoomOut));
		CC_BREAK_IF(! pZoomOut);

		// Place the menu item bottom-right conner.
		pZoomOut->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width - 25, 25));

		// Create a menu with the "close" menu item, it's an auto release object.
		CCMenu* pMenu2 = CCMenu::create(pZoomOut, NULL);
		pMenu2->setPosition(CCPointZero);
		CC_BREAK_IF(! pMenu2);

		this->addChild(pMenu2,2,2);

		// Create a "close" menu item with close icon, it's an auto release object.
		CCMenuItemImage *pLayerSwitch = CCMenuItemImage::create(
			"r_overlays.png",
			"r_overlays.png",
			this,
			menu_selector(ControlLayer::layerswitch));
		CC_BREAK_IF(! pLayerSwitch);

		// Place the menu item bottom-right conner.
		pLayerSwitch->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width/2, CCDirector::sharedDirector()->getWinSize().height-25));

		// Create a menu with the "close" menu item, it's an auto release object.
		CCMenu* pMenu3 = CCMenu::create(pLayerSwitch, NULL);
		pMenu3->setPosition(CCPointZero);
		CC_BREAK_IF(! pMenu3);

		// Add the menu to HelloWorld layer as a child layer.
		this->addChild(pMenu3, 3,3);

		m_ScaleList.reserve(19);
		for (int i=0;i<19;++i)
		{
			CCString str;
			str.initWithFormat("scale%d.png",i+1);
			CCMenuItemImage *pScaleItem = CCMenuItemImage::create(str.getCString(),str.getCString());
			CC_BREAK_IF(! pScaleItem);

			// Place the menu item bottom-right conner.
			pScaleItem->setPosition(ccp(100, 35));

			// Create a menu with the "close" menu item, it's an auto release object.
			CCMenu* pScaleMenu = CCMenu::create(pScaleItem, NULL);
			pScaleMenu->setPosition(CCPointZero);
			pScaleMenu->retain();
			m_ScaleList.push_back(pScaleMenu);
		}

		int zoom = pControl->getZoomLevel();

		addChild(m_ScaleList[zoom-1],4,4);
	} while (0);
}
开发者ID:BlueEyes-Lin,项目名称:sunmap,代码行数:98,代码来源:ControlLayer.cpp

示例5: menu_selector

// 初始化顶部bar
void MessageView::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_message.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(MessageView::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,代码来源:MessageView.cpp

示例6: ccp

void PlayMenu::setupGUI()
{
//    this->schedule(schedule_selector(PlayMenu::timerForLifeCheck),1/60);
    {
        CCLabelTTF*  timerLabel=  CCLabelTTF::create(NEXT_LIFE_IN, GAME_LABEL_FONT_NATHAN, 29);
        //  coinsLabel->setColor(ccc3(87, 0, 5));
        timerLabel->setPosition(ccp(winSize.width/2-170,winSize.height/2+430));
        timerLabel->setColor(ccBLUE);
        timerLabel->setTag(KTAG_PLYMENU_COINSLBL);
//        this->addChild(timerLabel,11-KTAG_LAYERING_PARAM);

    }
    timerForLife=  CCLabelTTF::create("", GAME_LABEL_FONT_NATHAN, 29);
    //  coinsLabel->setColor(ccc3(87, 0, 5));
    timerForLife->setPosition(ccp(winSize.width/2-20,winSize.height/2+430));
    timerForLife->setColor(ccBLACK);
    timerForLife->setTag(KTAG_PLYMENU_COINSLBL);
//    this->addChild(timerForLife,11-KTAG_LAYERING_PARAM);
/// Total Life Left
//    {
//        CCLabelTTF*  TotalLifeLabel=  CCLabelTTF::create("", GAME_LABEL_FONT_NATHAN, 29);
//        //  coinsLabel->setColor(ccc3(87, 0, 5));
//        TotalLifeLabel->setPosition(ccp(winSize.width-120,winSize.height/2+430));
//        TotalLifeLabel->setColor(ccBLUE);
//        TotalLifeLabel->setTag(KTAG_Life_Count);
//        this->addChild(TotalLifeLabel,11-KTAG_LAYERING_PARAM);
//        string TotalLifeCount = static_cast<ostringstream*>( &(ostringstream() << GAME_SHARED_HANDLER->getLives()) )->str();
//        TotalLifeCount="Life Count " + TotalLifeCount;
//        TotalLifeLabel->setString(TotalLifeCount.c_str());
//        CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(PlayMenu::updateLifeCountLabel),N_LIFE_COUNT_UPDATED,NULL);
//    }
    
    
    //add bg.
    
    CCSprite* bckg = CCSprite::create(BACKGROUND);
    bckg->setPosition( ccp(winSize.width/2,winSize.height/2) );
    CCLOG("win size %f ",winSize.width);
    this->addChild(bckg, 0-KTAG_LAYERING_PARAM);
    
//    CCSprite *logobg = CCSprite::create(LOGO);
//    logobg->setPosition(ccp(winSize.width/2, winSize.height/2+(155)));
//    this->addChild(logobg);
    
    CCMenuItemImage *playMenuItem = CCMenuItemImage::create(PLAY_IMAGE, PLAY_IMAGE_PRESSED, this,menu_selector(PlayMenu::play));
//    facebookMenuItem =  CCMenuItemImage::create(FACEBOOK_LOGIN_IMAGE, FACEBOOK_LOGIN_IMAGE_PRESSED, this,menu_selector(PlayMenu::facebookConnect));
    
    
    
    CCMenu *menu = CCMenu::create(playMenuItem,NULL);
    
    menu->setPosition(ccp(0, 0));
    playMenuItem->setPosition(ccp(winSize.width/2, winSize.height/2-(275)));
//    facebookMenuItem->setPosition(ccp(winSize.width/2, winSize.height/2-(325)));
    
    this->setFBStatus();
    CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(PlayMenu::setFBStatus),N_USER_LOG_STATUS_CHANGED,NULL);
    

    this->checkAndAddRequestsMenu();
    CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(PlayMenu::checkAndAddRequestsMenu),N_REQUESTS_DATA_UPDATED,NULL);

    
    
    
    
    this->addChild(menu);
    
    
}
开发者ID:forcekillxx,项目名称:Shared,代码行数:70,代码来源:PlayMenu.cpp

示例7: menu_selector

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
    CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
                                        "CloseNormal.png",
                                        "CloseSelected.png",
                                        this,
                                        menu_selector(HelloWorld::menuCloseCallback));
    
	pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
                                origin.y + pCloseItem->getContentSize().height/2));

    // create menu, it's an autorelease object
    CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
    pMenu->setPosition(CCPointZero);
    this->addChild(pMenu, 1);
	
    /////////////////////////////
    // 3. add your codes below...

    // add a label shows "Hello World"
    // create and initialize a label
	char fontName[13] = {"airborne.ttf"};
	char myText[21] = {"Rendering"};
    CCLabelTTF* pLabel = CCLabelTTF::create(myText, fontName, 24);
    
    // position the label on the center of the screen
    pLabel->setPosition(ccp(350,50));
	pLabel->setColor(cocos2d::ccRED);
    // add the label as a child to this layer
    this->addChild(pLabel, 1);

   this->setTouchEnabled(true);
   
   /*this->schedule( schedule_selector(handleUserTouch) );*/  
    CCSprite* pSprite = CCSprite::create("bg.png");

    // position the sprite on the center of the screen
    pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
	
    // add the sprite as a child to this layer
    this->addChild(pSprite, 0);
	 
	//The code starts here.. all the assets are done by me and plist file and sprite file was generated with sprite packer.
	
	CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("SpriteColl1.plist");
	CCSpriteBatchNode *spriteSheet = CCSpriteBatchNode::create("SpriteColl1.png");
	this->addChild(spriteSheet);
	 

	CCSprite *sprite = CCSprite::createWithSpriteFrameName("Sprite1.png");
	this->addChild(sprite);
    sprite->setPosition(ccp(400,200));
	CCArray *moveFrames = CCArray::createWithCapacity(15);
	char str[100] = {0};
for (int i = 1; i <= 4; i++) 
{
	sprintf(str, "Sprite%d.png", i);
    CCSpriteFrame* pFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(str);

    moveFrames->addObject(pFrame);
}
CCAnimation *animation = CCAnimation::createWithSpriteFrames(moveFrames, 0.3f);
    // 14 frames * 1sec = 14 seconds
    sprite->runAction(CCRepeatForever::create(CCAnimate::create(animation)));

	
	
	this->loadController();
		 
    return true;
}
开发者ID:bishnucit,项目名称:Cocos2dx-JoyStick-CCRectIntersect,代码行数:87,代码来源:HelloWorldScene.cpp

示例8: ccpMid

KDbool MenuLayer::init ( KDvoid )
{
	if ( !CCLayer::init ( ) )
	{
		return KD_FALSE;
	}

	m_nIndexText  = 0;

	CCSprite*		pBackground = CCSprite::create ( "Image 816 at frame 10.jpg" );
	pBackground->setScale ( IOSSCALE );
	pBackground->setPosition ( ccpMid ( m_tContentSize ) );
	this->addChild ( pBackground );

	CCMenuItemFont::setFontName ( "Arial Bold.ttf" );
	CCMenuItemFont::setFontSize ( 18 );

	CCMenuItem*		pItemAchievement = CCMenuItemFont::create ( "Achievement" );
	CCMenuItem*		pItemLeaderboard = CCMenuItemFont::create ( "Leaderboard" );
	CCMenuItem*		pItemGetProps = CCMenuItemFont::create ( "GetProps" );			
	CCMenuItem*		pItemPlay = CCMenuItemImage::create ( "Image 822 at frame 10.jpg", "Image 823 alpha channel at frame 10.png", this, menu_selector ( MenuLayer::playGame ) );

	CCMenu*			pMenu = CCMenu::create ( pItemAchievement, pItemLeaderboard, pItemGetProps, pItemPlay, KD_NULL );
	pMenu->alignItemsHorizontallyWithPadding ( 18 );
	pMenu->setPosition ( m_tContentSize.cx / 2, m_tContentSize.cy / 2 - 50 );
	this->addChild ( pMenu );

    m_pTelScope = TeleScope::create ( );
    m_pTelScope->setPosition ( ccp ( 80, 60 ) );
    m_pTelScope->setOpacity ( 0 );
    pBackground->addChild ( m_pTelScope, 1 );

	m_aTexts [ 0 ] = CCSprite::create ( "Image 817 at frame 10.jpg" );
	m_aTexts [ 1 ] = CCSprite::create ( "Image 818 at frame 10.jpg" );
	m_aTexts [ 2 ] = CCSprite::create ( "Image 819 at frame 10.jpg" );
	m_aTexts [ 3 ] = CCSprite::create ( "Image 820 at frame 10.jpg" );

	m_aTexts [ 0 ]->setPosition ( ccp ( 156 / 2      , 264 / 2 ) );
	m_aTexts [ 1 ]->setPosition ( ccp ( 156 / 2 +  40, 264 / 2 ) );
	m_aTexts [ 2 ]->setPosition ( ccp ( 156 / 2 +  80, 264 / 2 ) );
	m_aTexts [ 3 ]->setPosition ( ccp ( 156 / 2 + 120, 264 / 2 ) );

	m_aTexts [ 0 ]->setOpacity ( 0 );
	m_aTexts [ 1 ]->setOpacity ( 0 );
	m_aTexts [ 2 ]->setOpacity ( 0 );
	m_aTexts [ 3 ]->setOpacity ( 0 );

	pBackground->addChild ( m_aTexts [ 0 ] );
	pBackground->addChild ( m_aTexts [ 1 ] );
	pBackground->addChild ( m_aTexts [ 2 ] );
	pBackground->addChild ( m_aTexts [ 3 ] );

	m_aHoles [ 0 ] = CCSprite::create ( "Image 824 at frame 10.jpg" );
	m_aHoles [ 1 ] = CCSprite::create ( "Image 824 at frame 10.jpg" );
	m_aHoles [ 2 ] = CCSprite::create ( "Image 824 at frame 10.jpg" );
	m_aHoles [ 3 ] = CCSprite::create ( "Image 824 at frame 10.jpg" );

	m_aHoles [ 0 ]->setOpacity ( 0 );
	m_aHoles [ 1 ]->setOpacity ( 0 );
	m_aHoles [ 2 ]->setOpacity ( 0 );
	m_aHoles [ 3 ]->setOpacity ( 0 );

	m_aHoles [ 0 ]->setPosition ( ccp (  58, 142 ) );
	m_aHoles [ 1 ]->setPosition ( ccp (  88, 112 ) );
	m_aHoles [ 2 ]->setPosition ( ccp ( 226, 105 ) );
	m_aHoles [ 3 ]->setPosition ( ccp ( 178, 132 ) );

	pBackground->addChild ( m_aHoles [ 0 ] );
	pBackground->addChild ( m_aHoles [ 1 ] );
	pBackground->addChild ( m_aHoles [ 2 ] );
	pBackground->addChild ( m_aHoles [ 3 ] );
    
	SimpleAudioEngine::sharedEngine ( )->preloadEffect ( "Sound 1 at frame 10.mp3" );
	SimpleAudioEngine::sharedEngine ( )->preloadEffect ( "Sound 5 at frame 10.mp3" );
	SimpleAudioEngine::sharedEngine ( )->preloadEffect ( "Sound 3 at frame 10.mp3" );

	return KD_TRUE;
}
开发者ID:mcodegeeks,项目名称:OpenKODE-Framework,代码行数:78,代码来源:MenuLayer.cpp

示例9: sprintf

bool OverMenu::init(CCNode* layer_)
{
    if(!CCLayer::init()){
        return false;
    }
    layer=layer_;

    layer->addChild(this,50);
    this->schedule(schedule_selector(OverMenu::tick));

    
    int score=((GameLayer*)layer)->gamebody->score;
    if(((GameLayer*)layer)->gamebody->game_mode==MODE_SHUANGZI){
        score=((GameLayer*)layer)->gamebody->score+((GameLayer*)layer)->gamebody2->score;
    }
    
    bool ishigh=false;
    
    int modeid=CCUserDefault::sharedUserDefault()->getIntegerForKey("gamemode");
    char modehighscore[200];
    sprintf(modehighscore, "highscore%d",modeid);
    int highscore=CCUserDefault::sharedUserDefault()->getIntegerForKey(modehighscore);
    if(score>highscore){
        highscore=score;
        CCUserDefault::sharedUserDefault()->setIntegerForKey(modehighscore, highscore);
        CCUserDefault::sharedUserDefault()->flush();
        ishigh=true;
        CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("sound/newscore.mp3", false);
    }
    
    
    
    
    {
        CCMenuItemImage *button = CCMenuItemImage::create(
                                                          "game/black.jpg",
                                                          "game/black.jpg",
                                                          this,
                                                          NULL );
        CCMenu* Menu = CCMenu::create(button, NULL);
        Menu->setPosition(CCPointZero);
        this->addChild(Menu,-1);
        button->setAnchorPoint(ccp(0.5f,0));
        button->setPosition(ccp(screenSize.width*0.5f,0));
        button->setOpacity(150);
    }
    
    
    {
        pane=CCSprite::create("over/back.png");
        this->addChild(pane,1);
        pane->setScale(0.3f*screenSize.height/pane->getContentSize().height);
        pane->setPosition(ccpPercent(50, 155));
        
        {
            CCMoveTo* a1=CCMoveTo::create(0.4f, ccpPercent(50, 60));
            pane->runAction(a1);
        }
        
        {
            CCLabelTTF* word = CCLabelTTF::create("游戏结束", "ttf/word.ttf", pane->getContentSize().height*0.2f);
            word->setAnchorPoint(ccp(0.5f,0.5f));
            pane->addChild(word, 10);
            word->setPosition(ccpContent(pane->getContentSize(), 50, 120));
            word->setColor(ccGRAY);
        }
        
        {
            char* name;
            GAME_MODE gamemode=((GameLayer*)layer)->game_mode;
            char* gamecenterid;
            if(gamemode==MODE_WANMEI){
                name=(char*)"完美模式";
                gamecenterid=(char*)"com.adultdream.mengmengda.wanmei";
            }
            if(gamemode==MODE_SHANDIAN){
                name=(char*)"闪电模式";
                gamecenterid=(char*)"com.adultdream.mengmengda.shandian";
            }
            if(gamemode==MODE_NIUZHUAN){
                name=(char*)"扭转模式";
                gamecenterid=(char*)"com.adultdream.mengmengda.niuzhuan";
            }
            if(gamemode==MODE_SHUANGZI){
                name=(char*)"双子模式";
                gamecenterid=(char*)"com.adultdream.mengmengda.shuangzi";
            }
            if(gamemode==MODE_XIANSHI){
                name=(char*)"限时模式";
                gamecenterid=(char*)"com.adultdream.mengmengda.xianshi";
            }
            if(gamemode==MODE_JINGDIAN){
                name=(char*)"经典模式";
                gamecenterid=(char*)"com.adultdream.mengmengda.jingdian";
            }
            
            CCLabelTTF* word = CCLabelTTF::create(name, "ttf/word.ttf", pane->getContentSize().height*0.15f);
            word->setAnchorPoint(ccp(0.5f,0.5f));
            pane->addChild(word, 10);
            word->setPosition(ccpContent(pane->getContentSize(), 50, 80));
//.........这里部分代码省略.........
开发者ID:k2inGitHub,项目名称:QZ_Stack,代码行数:101,代码来源:OverMenu.cpp

示例10: menu_selector

bool ChuanqiduanzaoItem::initItem(BaseActor* info)
{
	bool bret = false;

	//初始化背景
	if (CCSprite::initWithFile("shangdian_chuanqi_bg.png"))
	{
		bret = true;
	}

	if (bret)
	{
		m_Profession_id = info->getCurrentProperty().profession;
		//顶部文字显示
		CCLabelTTF* pTopTip = CCLabelTTF::create(LFStrings::getValue("ShenBingDuanZao_ShuoMingTiShi").c_str(), fontStr_kaiti, 18);
		pTopTip->setPosition(ccp(this->getContentSize().width/2, this->getContentSize().height-70));
		pTopTip->setColor(fonColor_FaGuang);
		this->addChild(pTopTip);

		//头像
		CCSprite* pIcon = CCSprite::create(this->getIconFileNameByType(info->getActorType()).c_str());
		this->addChild(pIcon);
		pIcon->setPosition(ccp(this->getContentSize().width/2, 400));

		//美术字(英雄类型)
		CCSprite* pHeroType = CCSprite::create(this->getHeroTypeFileNameByType(info->getActorType()).c_str());
		this->addChild(pHeroType);
		pHeroType->setPosition(ccp(this->getContentSize().width/2, 
			pIcon->getPositionY()-pIcon->getContentSize().height/2-pHeroType->getContentSize().height+2));


		//套装名字
		string zhuangBeiStr = ChuanqiPool::getPool()->getChuanQiSuitName(info->getActorType());
		CCLabelTTF* pName = CCLabelTTF::create(zhuangBeiStr.c_str(), fontStr_kaiti, 20);
		pName->setPosition(ccp(this->getContentSize().width/2, 280));
		this->addChild(pName);

		CCMenu* pMenu = CCMenu::create();
		this->addChild(pMenu);
		pMenu->setPosition(CCPointZero);
		//锻造一次
		CCMenuItemImage *yici = CCMenuItemImage::create(
			"shangdian_shenbin_anniu_duanzaoyici.png",
			"shangdian_shenbin_anniu_duanzaoyici_select.png",
			this, menu_selector(ChuanqiduanzaoItem::menuItemClicked_DuanZao));
		pMenu->addChild(yici, 0, Tag_MenuItem_Yici);
		yici->setPosition(ccp(this->getContentSize().width/2-yici->getContentSize().width/2, 185));
		yici->setUserData((void*)info->getActorType());

		//锻造十次
		CCMenuItemImage *shici = CCMenuItemImage::create(
			"shangdian_shenbin_anniu_duanzaoshici.png",
			"shangdian_shenbin_anniu_duanzaoshici_select.png",
			this, menu_selector(ChuanqiduanzaoItem::menuItemClicked_DuanZao));
		pMenu->addChild(shici, 0, Tag_MenuItem_Shici);
		shici->setPosition(ccp(this->getContentSize().width/2+yici->getContentSize().width/2, yici->getPositionY()));
		shici->setUserData((void*)info->getActorType());

		char buf[20];
		//锻造一次需要金币
		BaseSprite *goldIcon1 = BaseSprite::create("jinbi_tubiao.png");
		this->addChild(goldIcon1);
		goldIcon1->setScale(0.5f);
		goldIcon1->setPosition(ccp(yici->getPositionX()-goldIcon1->getContentSize().width/2, yici->getPositionY()+yici->getContentSize().height/2+goldIcon1->getContentSize().height/2));
		sprintf(buf, "%d", 400);
		CCLabelTTF *yiciLabel = CCLabelTTF::create(buf, fontStr_BookAntiqua, 20);
		this->addChild(yiciLabel);
		yiciLabel->setPosition(ccp(goldIcon1->getPositionX()+goldIcon1->getContentSize().width/2*goldIcon1->getScaleX()+yiciLabel->getContentSize().width/2
			, goldIcon1->getPositionY()));
		//锻造十次需要金币
		BaseSprite *goldIcon10 = BaseSprite::create("jinbi_tubiao.png");
		this->addChild(goldIcon10);
		goldIcon10->setScale(0.5f);
		goldIcon10->setPosition(ccp(shici->getPositionX()-goldIcon10->getContentSize().width/2, shici->getPositionY()+shici->getContentSize().height/2+goldIcon10->getContentSize().height/2));
		sprintf(buf, "%d", 400*10);
		CCLabelTTF *yiciLabel0 = CCLabelTTF::create(buf, fontStr_BookAntiqua, 20);
		this->addChild(yiciLabel0);
		yiciLabel0->setPosition(ccp(goldIcon10->getPositionX()+goldIcon10->getContentSize().width/2*goldIcon10->getScaleX()+yiciLabel0->getContentSize().width/2
			, goldIcon10->getPositionY()));

		CCMenuItemImage* pXiaoguo = CCMenuItemImage::create(
			"shandian_anniu_taozhuangxiaoguo.png",
			"shandian_anniu_taozhuangxiaoguo_select.png",
			this, menu_selector(ChuanqiduanzaoItem::menuItemClicked_Xiaoguo)
			);
		pMenu->addChild(pXiaoguo);
		pXiaoguo->setPosition(ccp(this->getContentSize().width/2, pXiaoguo->getContentSize().height/2));
	}

	return bret;
}
开发者ID:longguai,项目名称:game-DarkWar,代码行数:91,代码来源:ChuanqiduanzaoLayerScrollView.cpp

示例11: sprintf

bool PlayScene::init()
{
	bool bRet = false;
	do 
	{
		winSize = CCDirector::sharedDirector()->getWinSize();
		isPause = false;
		
		//this->registerWithTouchDispatcher();
		this->setKeypadEnabled(true);
		int lvl = CCUserDefault::sharedUserDefault()->getIntegerForKey("lvl");
		if(lvl == 0)
		{
			lvl = 1;
			CCUserDefault::sharedUserDefault()->setIntegerForKey("lvl",1);
		}
		char mapPath[20];
		char lvlinform[30];
		//map_tmx_lvl1
		sprintf(mapPath,"map/lvl%d.tmx",lvl);
		sprintf(lvlinform,"Lvl %d",lvl);
		isOver = -1;

		CCLabelTTF * lvlInform = CCLabelTTF::create(lvlinform, "Thonburi", 64);
		lvlInform->setPosition(ccp(-100,winSize.height/2));
		this->addChild(lvlInform,3);

		overinfor = CCLabelTTF::create("Game Over", "Thonburi", 64);
		overinfor->setPosition(ccp(winSize.width/2,winSize.height/2));
		overinfor->setVisible(false);
		this->addChild(overinfor,3);
		//这里是暂停菜单信息s

		lvlInform->runAction(CCJumpTo::create(3,ccp(winSize.width+100,winSize.height/2),60,10));
		ccColor4B t;
		t.a = 200;
		t.r = 0;
		t.g = 0;
		t.b = 0;
		pauseLayer = CCLayerColor::create(t);
		this->addChild(pauseLayer,10);
		pauseLayer->setPosition(CCPointZero);
		CCSprite *pauseBg = CCSprite::create(pause_bg);
		pauseBg->setPosition(ccp(winSize.width/2 , winSize.height/2));
		pauseLayer->addChild(pauseBg);
		
		CCMenuItemImage *resume = CCMenuItemImage::create(
			pause_resume,
			pause_resume,
			this,
			menu_selector(PlayScene::menuResume_CallBack)
			);
		
		CCMenuItemImage *save = CCMenuItemImage::create(
			pause_save,
			pause_save,
			this,
			menu_selector(PlayScene::menuSaveCallBack)
			);


		CCMenuItemImage *returnMenu = CCMenuItemImage::create(
			pause_return,
			pause_return,
			this,
			menu_selector(PlayScene::menuReturnCallBack)
			);

		CCMenu * pauseMenu = CCMenu::create(resume,save,returnMenu,NULL);
		pauseMenu->alignItemsVerticallyWithPadding(30);
		pauseLayer->addChild(pauseMenu);
		pauseLayer->setVisible(false);



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


		Mediator::getInstance()->release();   //释放
		Mediator::getInstance()->init();   //初始化
		//加载地图
		map = TmxMap::initMap(mapPath);  // 地图
		this->addChild(map);
		//添加摇杆,如果宏定义是手机
#ifdef IAMPHONE__
		CCSprite * bg = CCSprite::create(control_bg);
		CCSprite * cen = CCSprite::create(control_ce);
		control = Joystick::JoystickWithCenter(ccp(120,120),100.f,cen,bg);
		control->Active();
		this->addChild(control,1);
		control->setOpacity((float)0.3);
		//按钮
		fire = CCMenuItemImage::create(
			fire_normal,
			fire_press
			);
		fire->setOpacity(0.3*255);
		fire->setPosition(ccp(winSize.width - fire->getContentSize().width/2 - 10 , fire->getContentSize().height/2 + 10));
		CCMenu * menu = CCMenu::create(fire,NULL);
		menu->setPosition(CCPointZero);
//.........这里部分代码省略.........
开发者ID:jiangliwu,项目名称:tank-war-light,代码行数:101,代码来源:PlayScene.cpp

示例12: CC_BREAK_IF

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    bool bRet = false;
    do 
    {
        //////////////////////////////////////////////////////////////////////////
        // super init first
        //////////////////////////////////////////////////////////////////////////

        CC_BREAK_IF(! CCLayer::init());

        //////////////////////////////////////////////////////////////////////////
        // add your codes below...
        //////////////////////////////////////////////////////////////////////////
		
		CCSize size = CCDirector::sharedDirector()->getWinSize();				

        // 1. Add a menu item with "X" image, which is clicked to quit the program.

        // Create a "close" menu item with close icon, it's an auto release object.
        CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
            "CloseNormal.png",
            "CloseSelected.png",
            this,
            menu_selector(HelloWorld::menuCloseCallback));
        CC_BREAK_IF(! pCloseItem);

        // Place the menu item bottom-right conner.
        pCloseItem->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20));

        // Create a menu with the "close" menu item, it's an auto release object.
        CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
        pMenu->setPosition(CCPointZero);
        CC_BREAK_IF(! pMenu);

        // Add the menu to HelloWorld layer as a child layer.
        this->addChild(pMenu, 1);

        //// 2. Add a label shows "Hello World".
        //// Create a label and initialize with string "Hello World".
        //CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24);
        //CC_BREAK_IF(! pLabel);
        //// Get window size and place the label upper.         
        //pLabel->setPosition(ccp(size.width / 2, size.height - 50));
        //// Add the label to HelloWorld layer as a child layer.
        //this->addChild(pLabel, 1);

        // 3. Add add a splash screen, show the cocos2d splash image.
  //      pSprite = CCSprite::create("HelloWorld.png");
  //      CC_BREAK_IF(! pSprite);
  //      pSprite->setPosition(ccp(size.width/3, size.height/3));
		//pSprite->setAnchorPoint(ccp(0, 0));
  //      this->addChild(pSprite, 0);

		CCTMXTiledMap* tileMap = CCTMXTiledMap::tiledMapWithTMXFile("tmx/orthogonal.tmx");
		this->addChild(tileMap, -1, TileMapNode);
		CCTMXLayer* eventLayer = tileMap->layerNamed("GameEventLayer");
		eventLayer->setVisible(false);
		
		//tileMap->layerNamed("WinterLayer")->setVisible(false);
		//tileMap->layerNamed("Background")->setVisible(false);		

		this->setTouchEnabled(true);

        bRet = true;
    } while (0);

    return bRet;
}
开发者ID:bboy0623,项目名称:testcocos2d,代码行数:70,代码来源:HelloWorldScene.cpp

示例13: init

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
 //   CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
 //                                       "CloseNormal.png",
 //                                       "CloseSelected.png",
 //                                       this,
 //                                       menu_selector(HelloWorld::menuCloseCallback));
 //   
	//pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
 //                               origin.y + pCloseItem->getContentSize().height/2));

 //   // create menu, it's an autorelease object
 //   CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
 //   pMenu->setPosition(CCPointZero);
 //   this->addChild(pMenu, 1);

 //   /////////////////////////////
 //   // 3. add your codes below...

 //   // add a label shows "Hello World"
 //   // create and initialize a label
 //   
 //   CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24);
 //   
 //   // position the label on the center of the screen
 //   pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
 //                           origin.y + visibleSize.height - pLabel->getContentSize().height));

 //   // add the label as a child to this layer
 //   this->addChild(pLabel, 1);

    // add "HelloWorld" splash screen"
    CCSprite* pSprite = CCSprite::create("HelloWorld.png");

    // position the sprite on the center of the screen
    pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));

    // add the sprite as a child to this layer
    this->addChild(pSprite, 0);

	//CCSprite* pSprite = CCSprite::create("HelloWorld.png");
 //   // position the sprite on the center of the screen
 //   pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
 //   // add the sprite as a child to this layer
 //   this->addChild(pSprite, 0);

	/*CCMenuItemLabel* labTtf = CCMenuItemLabel::create(CCLabelTTF::create("lable Menu Test","Arial",20),this,menu_selector(HelloWorld::clickImage));
	labTtf->setPosition(ccp(visibleSize.width/2,visibleSize.height/10));
	CCMenu *pMenuLabl = CCMenu::create(labTtf,NULL);
	pMenuLabl->setPosition(CCPointZero);
	this->addChild(pMenuLabl,1);*/

	CCMenuItem *pImage = CCMenuItemImage::create("CloseNormal.png","CloseSelected.png",this,menu_selector(HelloWorld::clickImage));
	pImage->setPosition(visibleSize.width - pImage->getContentSize().width/2,visibleSize.height/2);
	CCMenu *pMenu = CCMenu::create(pImage,NULL);
	pMenu->setPosition(CCPointZero);
	this->addChild(pMenu,1);

	return true;
}
开发者ID:HUjinshuai,项目名称:-,代码行数:76,代码来源:HelloWorldScene.cpp

示例14: addChild

bool Level::init()
{
    if (!CCLayer::init()) {
        return false;
    }
    /*预加载音效*/
    SimpleAudioEngine::sharedEngine()->preloadEffect("confirm.mp3");
    
    /*添加背景*/
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    CCSprite* spBackGround = CCSprite::create("levelBackground.png");
    spBackGround->setPosition(ccp(size.width*0.5, size.height*0.5));
    addChild(spBackGround);
    
    /*创建图片菜单项*/
    CCMenuItemImage *item1 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel1));
    CCMenuItemImage *item2 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel2));
    CCMenuItemImage *item3 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel3));
    CCMenuItemImage *item4 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel4));
    CCMenuItemImage *item5 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel5));
    
    /*创建返回菜单项*/
    CCMenuItemImage *itemBack = CCMenuItemImage::create("display_back.png", "display_back.png", this, menu_selector(Level::backToMenu));;
    
    /*设置菜单项大小*/
    item1->setScale(0.45);
    item2->setScale(0.45);
    item3->setScale(0.45);
    item4->setScale(0.45);
    item5->setScale(0.45);
    
    /*创建菜单*/
    CCMenu* menu1 = CCMenu::create(item1, item2, item3, item4, item5, NULL);
    menu1->setPosition(ccp(size.width * 0.5, size.height * 0.55));
    menu1->alignItemsHorizontallyWithPadding(70);
    
    CCMenu* menuBack = CCMenu::create(itemBack, NULL);
    addChild(menuBack);
    menuBack->setPosition(ccp(size.width * 0.36, size.height * 0.05));
    menuBack->setScale(0.7);
    menuBack->setColor(ccc3(0, 32, 240));
    
    /*创建图片菜单项*/
    CCMenuItemImage *item6 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel6));
    CCMenuItemImage *item7 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel7));
    CCMenuItemImage *item8 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel8));
    CCMenuItemImage *item9 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel9));
    CCMenuItemImage *item10 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel10));
    
    /*设置菜单项大小*/
    item6->setScale(0.45);
    item7->setScale(0.45);
    item8->setScale(0.45);
    item9->setScale(0.45);
    item10->setScale(0.45);
    
    /*创建菜单*/
    CCMenu* menu2 = CCMenu::create(item6, item7, item8, item9, item10, NULL);
    
    menu2->setPosition(ccp(size.width * 1.5, size.height * 0.55));
    menu2->alignItemsHorizontallyWithPadding(70);
    
    /*-----------------------*/
    /*创建图片菜单项*/
    CCMenuItemImage *item11 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel11));
    CCMenuItemImage *item12 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel12));
    CCMenuItemImage *item13 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel13));
    CCMenuItemImage *item14 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel14));
    CCMenuItemImage *item15 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel15));
    
    /*设置菜单项大小*/
    item11->setScale(0.45);
    item12->setScale(0.45);
    item13->setScale(0.45);
    item14->setScale(0.45);
    item15->setScale(0.45);
    
    /*创建菜单*/
    CCMenu* menu3 = CCMenu::create(item11, item12, item13, item14, item15, NULL);
    
    menu3->setPosition(ccp(size.width * 2.5, size.height * 0.55));
    menu3->alignItemsHorizontallyWithPadding(70);
    
    /*添加关卡锁*/
    lock2 = CCSprite::create("lock.png");
    lock3 = CCSprite::create("lock.png");
    lock4 = CCSprite::create("lock.png");
    lock5 = CCSprite::create("lock.png");
    lock6 = CCSprite::create("lock.png");
    lock7 = CCSprite::create("lock.png");
    lock8 = CCSprite::create("lock.png");
    lock9 = CCSprite::create("lock.png");
    lock10 = CCSprite::create("lock.png");
    lock11 = CCSprite::create("lock.png");
    lock12 = CCSprite::create("lock.png");
    lock13 = CCSprite::create("lock.png");
    lock14 = CCSprite::create("lock.png");
    lock15 = CCSprite::create("lock.png");
    
    item2->addChild(lock2);
//.........这里部分代码省略.........
开发者ID:DustinJia,项目名称:Alliance-Warfare,代码行数:101,代码来源:Level.cpp

示例15: setTouchEnabled

bool StoryWorld::init() {
    if ( !CCLayer::init() )
    {
        return false;
    }

    char theName[10][11]={"","穆婧:", "子轩:", "少杰:", "建国", "路人A:", "路人B:", "路人C:", "老爷爷:", "江姐:"};
    char play[20] = SCRIPT_PATH;
    int current=sGlobal->mapState->storyCnt+'0';//stay
    play[SCRIPT_PATH_LEN] = current;
    reader.ReadFileWithFullPath(CCFileUtils::sharedFileUtils()->fullPathForFilename(play));
    setTouchEnabled(true);
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
    CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
                                        CLOSEN_IMG_PATH, CLOSES_IMG_PATH, this, menu_selector(StoryWorld::menuCloseCallback)); 
	pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
                                origin.y + pCloseItem->getContentSize().height/2));
    
    CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
    pMenu->setPosition(CCPointZero);
    addChild(pMenu, 2);
    
    char bg_name[30] = BGNAME_IMG_PATH;
    bg_name[BGNAME_PATH_LEN] = current;
    CCSprite* pBackground = CCSprite::create(bg_name);
    pBackground->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    pBackground->setScale(1);
    pBackground->setTag(108);
    addChild(pBackground, 0);
    
    CCSprite* dialogBox = CCSprite::create(DUIHUAKUANG_IMG_PATH);
    dialogBox->setPosition(ccp(visibleSize.width/2, dialogBox->getContentSize().height/2));
    dialogBox->setOpacity(220);
    addChild(dialogBox,1);
    
    CCLabelTTF* pName = CCLabelTTF::create(theName[0], "Heiti SC", 40);
    pName->setTag(101);
    pName->setPosition(ccp(pName->getContentSize().width/2, dialogBox->getContentSize().height - 2 * pName->getContentSize().height));
    pName->setAnchorPoint(CCPointZero);
    addChild(pName, 1);
    
    CCLabelTTF* pLabel = CCLabelTTF::create("Click to Start", "Heiti SC", 40);
    pLabel->setTag(100);
    pLabel->setPosition(ccp(40, origin.y + dialogBox->getContentSize().height - 3.4 * pLabel->getContentSize().height));
    pLabel->setAnchorPoint(CCPointZero);
    pLabel->setDimensions(CCSizeMake(1100, 0));
    pLabel->setHorizontalAlignment(kCCTextAlignmentLeft);
    addChild(pLabel, 1);
    
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(PLIST_IMG_PATH);
    CCSpriteBatchNode *spriteBatch=CCSpriteBatchNode::create(VDRAWING_IMG_PATH);
    spriteBatch->setTag(102);
    addChild(spriteBatch, 0);
    spriteBatch->setPosition(CCPointZero);

    CCSprite *leftSprite=CCSprite::createWithSpriteFrameName("me_1.png");
    leftSprite->setScale(0.8);
    leftSprite->setPosition(ccp(leftSprite->getContentSize().width*0.8, leftSprite->getContentSize().height/2 *0.8));
    leftSprite->setTag(1);
    leftSprite->setOpacity(0);
    spriteBatch->addChild(leftSprite, 0);
    
    CCSprite *rightSprite=CCSprite::createWithSpriteFrameName("blank.png");
    rightSprite->setPosition(ccp(800, 130));
    rightSprite->setTag(2);
    rightSprite->setOpacity(0);
    spriteBatch->addChild(rightSprite, 0);
    
    avgGame();
    return true;
}
开发者ID:davidxk,项目名称:Blue-MY-Lake,代码行数:72,代码来源:Story.cpp


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