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


C++ CCMenuItemImage类代码示例

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


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

示例1: callfuncO_selector

// on "init" you need to initialize your instance
bool ChooseMap::init()
{
    //////////////////////////////
    // 1. super init first
    if (!Layer::init())
    {
        return false;
    }
    CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(ChooseMap::getArray), "2PMessage", NULL);
    CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(ChooseMap::storymode), "storyMessage", NULL);
    string path = "images/newGame/";
	char *mapName[6] = { "chibi", "guandu", "hanzhong", "hulaoguan", "xuzhou", "yiling"};
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    //平铺背景
    auto *bg = CCSprite::create("images/background/bg_fight.png");
    bg->setPosition(ccp(visibleSize.width / 2, visibleSize.height / 2));
    this->addChild(bg, -1);
    //标题
    auto *title = CCSprite::create(path + "map_choose.png");
    title->setPosition(ccp(visibleSize.width * 0.1, visibleSize.height * 0.9));
    this->addChild(title);
    title->setScale(1.4f, 1.4f);
    //hint
    string hints = XMLParser::parseXML("hintStrings", 3);
    CCLabelTTF *ttf = CCLabelTTF::create(hints, "【朦胧补】水黑体", 35);
    ttf->setPosition(ccp(visibleSize.width * 0.85, visibleSize.height * 0.87));
    this->addChild(ttf);
    //上一步
    auto* last = CCSprite::create(path+"last.png");
    last->setScale(1.4f, 1.4f);
    auto* last_selected = CCSprite::create(path + "last_selected.png");
    last_selected->setScale(1.4f, 1.4f);
    auto *Last = CCMenuItemSprite::create(last, last_selected, last, this, menu_selector(ChooseMap::backto));
    Last->setPosition(ccp(visibleSize.width - 200, 50));
    //开始游戏
    auto* begin = CCSprite::create(path + "begin.png");
    begin->setScale(1.4f, 1.4f);
    auto* begin_selected = CCSprite::create(path + "begin_selected.png");
    begin_selected->setScale(1.4f, 1.4f);
    auto *Begin = CCMenuItemSprite::create(begin, begin_selected, begin, this, menu_selector(ChooseMap::startGame));
    Begin->setPosition(ccp(visibleSize.width - 80, 50));

    auto *menu = CCMenu::create(Begin, NULL);
    menu->addChild(Last, NULL);
    menu->setPosition(Point::ZERO);
    this->addChild(menu, 2);

	auto listener = EventListenerTouchOneByOne::create();
    listener->setSwallowTouches(true);
    listener->onTouchBegan = [](Touch* touch, Event* event)->bool{
        CCLOG("listener1 onTouchBegan");
        auto target = static_cast<Sprite*>(event->getCurrentTarget());
        Point locationInNode = target->convertToNodeSpace(touch->getLocation());
        Size s = target->getContentSize();
        Rect rect = Rect(0, 0, s.width, s.height);
        if (rect.containsPoint(locationInNode)){//判断触摸点是否在目标的范围内
            return true;
        }
        else
            return false;
    };
    listener->onTouchMoved = [](Touch* touch, Event* event){CCLOG("listener1 onTouchMoved"); };
    listener->onTouchEnded = [](Touch* touch, Event* event){
        CCMenuItemImage *target = static_cast< CCMenuItemImage*>(event->getCurrentTarget());
        if (target->isSelected()){
            target->unselected();
        }
        else {
	        SimpleAudioEngine::sharedEngine()->playEffect("select.wav",false);//开始播放背景音效,false表示不循环
            target->selected();
        }
    };
    for (int k = 0; k < 2; k++){
        double f;
        if (k == 0){
            f = 0.58;
        }
        else {
            f = 0.23;
        }
        for (int j = 0; j < 3; j++){
			int i = 3 * k + j;
            Sprite *sprite = Sprite::create(path + mapName[i] + ".png");
            sprite->setScale(0.5f, 0.5f);
            map[i] = CCMenuItemImage::create(path + mapName[i] + "zhizhan.png", path + mapName[i] + "zhizhan_selected.png");
            map[i]->setScale(0.5f, 0.5f);
            sprite->setPosition(ccp(visibleSize.width * 0.3 * j + 280, visibleSize.height * f - 50));
            map[i]->setPosition(ccp(visibleSize.width * 0.3 * j + 280, visibleSize.height * f + 80));
            this->addChild(sprite);
            this->addChild(map[i], 1);
            _eventDispatcher->addEventListenerWithSceneGraphPriority(listener->clone(), map[i]);
        }
    }
    return true;
}  
开发者ID:Angusnut,项目名称:zhanqi,代码行数:97,代码来源:ChooseMap.cpp

示例2: 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...
        //////////////////////////////////////////////////////////////////////////

        // 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);

		CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
		CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
		CCLog("Origin: (%.3f, %.3f)\n", origin.x, origin.y);
        // Place the menu item bottom-right conner.
        pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2,
									origin.y + pCloseItem->getContentSize().height/2));

        // 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, ZORDER_UI);

        // 2. background
		m_pSpaceDust = CCSprite::create("bg_front_spacedust.png");
		m_pSpaceDust->setPosition(ccp(origin.x + visibleSize.width/2, origin.y + visibleSize.height));
		m_pPlanetSunrise = CCSprite::create("bg_planetsunrise.png");
		m_pPlanetSunrise->setPosition(ccp(origin.x + visibleSize.width, origin.y + visibleSize.height*0.9f));
		m_pGalaxy = CCSprite::create("bg_galaxy.png");
		m_pGalaxy->setPosition(ccp(origin.x + visibleSize.width*0.0f, origin.y + visibleSize.height*0.5f));
		//m_pSpacialAnomaly = CCSprite::create("bg_spacialanomaly.png");
		//m_pSpacialAnomaly->setPosition(ccp(origin.x + visibleSize.width*0.3f, origin.y + visibleSize.height*0.7f));
		m_pSpacialAnomaly2 = CCSprite::create("bg_spacialanomaly2.png");
		m_pSpacialAnomaly2->setPosition(ccp(origin.x + visibleSize.width, origin.y + visibleSize.height*0.1f));

		this->addChild(m_pSpaceDust, ZORDER_BACKGROUND);
		this->addChild(m_pPlanetSunrise, ZORDER_BACKGROUND);
		this->addChild(m_pGalaxy, ZORDER_BACKGROUND);
		//this->addChild(m_pSpacialAnomaly, ZORDER_BACKGROUND);
		this->addChild(m_pSpacialAnomaly2, ZORDER_BACKGROUND);

		// 3. player
		m_pPlayer = CCSprite::create("spaceman_tiny.png");
		m_x = origin.x + visibleSize.width/2;
		m_y = origin.y + GROUND_HEIGHT;
		m_pPlayer->setPosition(ccp(m_x, m_y));
		this->addChild(m_pPlayer, ZORDER_PLAYER);

		// 4. planets
		m_pBatchNode = CCSpriteBatchNode::create("planets.pvr.ccz");
		this->addChild(m_pBatchNode, ZORDER_INTERACTIVE);
		CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("planets.plist");

		// 5. events
		this->scheduleUpdate();
		this->setTouchEnabled(true);
		this->schedule(schedule_selector(HelloWorld::gameLogic), 2.0f);

		// 6. other
		m_pPlanets = new CCArray;
		CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("SpaceGame.wav", true);

        bRet = true;
    } while (0);

    return bRet;
}
开发者ID:GraphicsMe,项目名称:StarTrek,代码行数:85,代码来源:HelloWorldScene.cpp

示例3: init

// on "init" you need to initialize your instance
bool MainMenu::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
    //CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("MainMenu-ipadhd.plist");
    //_menuBatchNode = CCSpriteBatchNode::create("MainMenu-ipadhd.png");
    
    //this->addChild(_menuBatchNode);
    
    auto CCSprite * sprite;
    sprite = CCSprite::create("mainmenucolor.png");
    sprite->setRotation(90.0f);
    sprite->setPosition(ccp(visibleSize.width/2,visibleSize.height/2));
    this->addChild(sprite,0);
    
    sprite = CCSprite::create("mainmenubull.png");
    sprite->setPosition(ccp(visibleSize.width/2-sprite->boundingBox().size.width/2.5,visibleSize.height-sprite->boundingBox().size.height/2));
    sprite->setScale(.95f);
    this->addChild(sprite);
    
    //sprite = CCSprite::createWithSpriteFrameName("playButton.png");
    //sprite->setPosition(ccp(visibleSize.width/2+sprite->boundingBox().size.width/2,visibleSize.height/2+sprite->boundingBox().size.height/2));
    //_menuBatchNode->addChild(sprite);
    
    
    CCMenuItemImage *playbutton = CCMenuItemImage::create("playButton.png","playButton.png",this,menu_selector(MainMenu::playButtonCallback));
    playbutton->setPosition(ccp(visibleSize.width/2+playbutton->boundingBox().size.width/2,visibleSize.height/2+playbutton->boundingBox().size.height/2));
    
    CCMenu* playMenu = CCMenu::create(playbutton, NULL);
    playMenu->setPosition(CCPointZero);
    this->addChild(playMenu, 1);
    
    CCMenuItemImage *quitbutton = CCMenuItemImage::create("quitbutton.png","quitbutton.png",this,menu_selector(MainMenu::menuCloseCallback));
    
    quitbutton->setPosition(ccp(visibleSize.width/2+quitbutton->boundingBox().size.width/2,visibleSize.height/4));
    
    CCMenu* quitMenu = CCMenu::create(quitbutton, NULL);
    quitMenu->setPosition(CCPointZero);
    this->addChild(quitMenu, 1);
    
    
    
    /////////////////////////////
    // 3. add your codes below...

    // add a label shows "Hello World"
    // create and initialize a label
    
    

    
    
    return true;
}
开发者ID:xgeraldx,项目名称:ChickenHunt,代码行数:69,代码来源:MainMenuScene.cpp

示例4: initButton

//添加顶部按钮
void MenuScene::initButton()
{
    //免费富币
    CCMenuItemImage *freeImage = CCMenuItemImage::create("ZF_Shoot_Button_coin.png", "ZF_Shoot_Button_coin1.png",this,menu_selector(MenuScene::menuCloseCallBack));
    freeImage->setPosition(ccp(size.width/2, size.height-55));
    freeImage->setTag(1);
    CCActionInterval* scaleTofree1 = CCScaleTo::create(kScaleDuration, 1, 0.95);
    CCActionInterval* scaleTofree2 = CCScaleTo::create(kScaleDuration, 0.96, 1);
    CCSequence* sequence1 = CCSequence::create(scaleTofree1,scaleTofree2,NULL);
    CCActionInterval* rotate1 = CCRepeatForever::create(sequence1);
    freeImage->runAction(rotate1);
    
    
    //商城
    CCMenuItemImage *buyImage = CCMenuItemImage::create("ZF_Shoot_Button_shop.png", "ZF_Shoot_Button_shop1.png",this,menu_selector(MenuScene::menuCloseCallBack));
    buyImage->setPosition(ccp(size.width/2+205, size.height-55));
    buyImage->setTag(2);
    CCActionInterval* scaleTobuy1 = CCScaleTo::create(kScaleDuration, 1, 0.95);
    CCActionInterval* scaleTobuy2 = CCScaleTo::create(kScaleDuration, 0.96, 1);
    CCSequence* sequence2 = CCSequence::create(scaleTobuy1,scaleTobuy2,NULL);
    CCActionInterval* rotate2 = CCRepeatForever::create(sequence2);
    buyImage->runAction(rotate2);
    
    
    //玩家指南
    CCMenuItemImage *guideIamge = CCMenuItemImage::create("ZF_Shoot_Button_help.png", "ZF_Shoot_Button_help1.png",this,menu_selector(MenuScene::menuCloseCallBack));
    guideIamge->setPosition(ccp(size.width/2+405, size.height-55));
    guideIamge->setTag(4);
    CCActionInterval* scaleTopl1 = CCScaleTo::create(kScaleDuration, 1, 0.95);
    CCActionInterval* scaleTopl2 = CCScaleTo::create(kScaleDuration, 0.96, 1);
    CCSequence* sequence4 = CCSequence::create(scaleTopl1,scaleTopl2,NULL);
    CCActionInterval* rotate4 = CCRepeatForever::create(sequence4);
    guideIamge->runAction(rotate4);
    
    sceneMenu = CCMenu::create(freeImage,buyImage,guideIamge,NULL);
    sceneMenu->setPosition(CCPointZero);
    this->addChild(sceneMenu, 1);
}
开发者ID:valentman,项目名称:Shoot,代码行数:39,代码来源:MenuScene.cpp

示例5: CC_BREAK_IF

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

		CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
		CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

		// 背景
		cocos2d::CCSprite *pSpriteBg = CCSprite::create( PATCH_RES_DIR("bg8.png") );
		pSpriteBg->setScale(BG_SCALE);
		pSpriteBg->setAnchorPoint( ccp(0, 0) );
		pSpriteBg->setPosition( ccp(0, 0) );
		addChild( pSpriteBg, 0 );

        // 关闭按钮
        CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
            PATCH_RES_DIR("close2.png"),
            PATCH_RES_DIR("close1.png"),
            this,
            menu_selector(CGroupInfoScene::menuCloseCallback) );
        CC_BREAK_IF( !pCloseItem );
		pCloseItem->setAnchorPoint( ccp(0, 0) );
		float w = visibleSize.width - pCloseItem->getContentSize().width - 5;
		float h = 5;
		pCloseItem->setPosition( ccp(w, h) );

        CCMenu *pMenu = CCMenu::create( pCloseItem, NULL );
        pMenu->setPosition( CCPointZero );
        CC_BREAK_IF( !pMenu );
        addChild( pMenu, 1 );

		// 后退
		{
			CCMenuItemImage *pBackItem = CCMenuItemImage::create(
				PATCH_RES_DIR("back.png"),
				PATCH_RES_DIR("back.png"),
				this,
				menu_selector(CGroupInfoScene::menuBackCallback) );
			CC_BREAK_IF( !pBackItem );
			pBackItem->setAnchorPoint( ccp(0, 0) );
			float w = visibleSize.width - pBackItem->getContentSize().width - 5 - pCloseItem->getContentSize().width;
			float h = 5;
			pBackItem->setPosition( ccp(w, h) );
			CCMenu *pMenu = CCMenu::create( pBackItem, NULL );
			pMenu->setPosition( CCPointZero );
			CC_BREAK_IF( !pMenu );
			addChild( pMenu, 1 );
		}

        bRet = true;

		// 群名字
		CGroupInfo *group = CGameManager::Instance().GetCurGroup();
		cocos2d::CCSprite *pGroupSprite = CCSprite::create( PATCH_RES_DIR("group.png") );
		pGroupSprite->setScale(BG_SCALE);
		pGroupSprite->setAnchorPoint( ccp(0, 0) );
		pGroupSprite->setPosition( ccp(10, visibleSize.height-pGroupSprite->getContentSize().height-5 ) );
		addChild( pGroupSprite, 0 );
		CCLabelTTF *labelGroup = CCLabelTTF::create(group->m_Name.c_str(), "Helvetica", 20.0);
		labelGroup->setAnchorPoint(CCPointZero);
		labelGroup->setPosition( ccp(pGroupSprite->getContentSize().width+20, visibleSize.height-pGroupSprite->getContentSize().height-5 ) );
		addChild( labelGroup, 0 );

		// 自己
		cocos2d::CCSprite *pSelf = CCSprite::create( PATCH_RES_DIR("group_self.png") );
		pSelf->setScale(BG_SCALE);
		pSelf->setAnchorPoint( ccp(0, 0) );
		pSelf->setPosition( ccp(visibleSize.width/2, visibleSize.height-pGroupSprite->getContentSize().height-5 ) );
		addChild( pSelf, 0 );
		CCLabelTTF *labelSelf = CCLabelTTF::create(CGameManager::Instance().GetUser().c_str(), "Helvetica", 20.0);
		labelSelf->setAnchorPoint(CCPointZero);
		labelSelf->setPosition( ccp(visibleSize.width/2+pSelf->getContentSize().width+20, visibleSize.height-pGroupSprite->getContentSize().height-5 ) );
		addChild( labelSelf, 0 );

		// 加载成员列表
		_InitMemberList();
		_InitAddGame();
			
		CNetManager::Instance().ResumeProcMsg();

		CGameManager::Instance().SetGameWorld( this );
    } while (0);

    return bRet;
}
开发者ID:mjssw,项目名称:myproj,代码行数:88,代码来源:GroupInfoScene.cpp

示例6: abs

bool ResultLayer::init() {
	if ( CCLayerColor::initWithColor( ccc4(255, 255, 255, 255) ) ) {
        
        CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
        CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
        
        // make the labels of the score and the high score and add them on the layer.
        int score = Score::getScore();
        int highScore = Score::getHighScore();
//        CCLog("score = %d", score);
//        CCLog("high score= %d", highScore);
        CCString* scoreValue = CCString::createWithFormat("Score: %d", score);
        CCString* highScoreValue = CCString::createWithFormat("High Score: %d", highScore);
        // set font.
        CCLabelTTF* pScoreLabel = CCLabelTTF::create(scoreValue->getCString(), "arial", 48.0);
        // set the font color
        pScoreLabel->setColor(ccc3(255, 0, 127));
        int widthScoreLabel =pScoreLabel->getContentSize().width;
         // set font.
        CCLabelTTF* pHighScoreLabel = CCLabelTTF::create(highScoreValue->getCString(), "arial", 48.0);
        // set the font color.
        pHighScoreLabel->setColor(ccc3(255, 0, 127));
        // get the width and the height of the high score label.
        int widthHighScoreLabel =pHighScoreLabel->getContentSize().width;
        int heightHighScoreLabel = pHighScoreLabel->getContentSize().height;
        // set the positions of the labels.
        pScoreLabel->setPosition(ccp(origin.x + visibleSize.width / 2 - widthScoreLabel / 2,
                                     origin.y + (int)(visibleSize.height * (1.0 - 0.4))));
        pHighScoreLabel->setPosition(ccp(origin.x + visibleSize.width / 2 - widthScoreLabel/ 2
                                         + abs(widthHighScoreLabel - widthScoreLabel) / 2,
                                         origin.y + (int)(visibleSize.height * (1.0 - 0.4))
                                         - heightHighScoreLabel - 20));
        // add the labels to the layer.
        this->addChild(pScoreLabel, 1);
        this->addChild(pHighScoreLabel, 1);
        
        
		// 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(
                                                              "BackNormal.png",
                                                              "BackSelected.png",
                                                              this,
                                                              menu_selector(ResultLayer::menuBackCallback));
        
		// Place the menu item bottom-right conner.
//        CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
//        CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
        
		pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2,
                                    origin.y + pCloseItem->getContentSize().height/2));
        
		// Create a menu with the "close" menu item, it's an auto release object.
		CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
		pMenu->setPosition(CCPointZero);
        
		// Add the menu to SecondWorld layer as a child layer.
		this->addChild(pMenu, 1);
        
        return true;
    } else {
        return false;
    }
}
开发者ID:andropenguin,项目名称:SimpleGameRev,代码行数:65,代码来源:Result.cpp

示例7:

CCMenuItemImage* Objects2dFactory::textButton(CCNode* scene, CCMenu* menu, string value, string normalImagePath, string selectedImagePath, string disabledImagePath, 
	float positionX, float positionY, float width, float height, SEL_MenuHandler selector, void* selectorArg, AlignX alignX, AlignY alignY, ccColor3B textColor, int zOrder)
{
	// Check arguments validity
	if(scene == NULL ||menu == NULL || !selector)
		return NULL;

	// Create a button menu item
    CCMenuItemImage *button = CCMenuItemImage::create(
        normalImagePath.c_str(),
        selectedImagePath.c_str(),
		disabledImagePath.c_str(),
        scene,
        selector);
    if(!button)
		return NULL;

	if (selectorArg != NULL)
	{
		button->setUserData(selectorArg);
	}

    // Place the menu item in the given position
    button->setPosition(ccp(positionX, positionY));

	// Set menu item anchor
	button->setAnchorPoint(ccp(Constants::getAnchorValue(alignX), Constants::getAnchorValue(alignY)));
	
	// Set menu item height
	float buttonHeight = button->boundingBox().size.height;
	float buttonPosScaleHeight = buttonHeight;
	if (height > 0) // if height is defined, it is setted
	{
		button->setScaleY(height / buttonHeight);
		buttonPosScaleHeight = height;
	}
	
    // Create a label and initialize with the given string
	CCLabelTTF* pLabel = CCLabelTTF::create(value.c_str(), "Arial"/*string(Constants::getResourcesPath() + "SOResources/Fonts/AlphaFridgeMagnetsAllCap.ttf").c_str()*/, 
		buttonPosScaleHeight * 0.6f);
    if(!pLabel)
		return NULL;
	
    // Set color
    pLabel->setColor(textColor);
	
	// Set menu item width
	float buttonWidth = button->boundingBox().size.width;
	float buttonPosScaleWidth = buttonWidth;
	if (width > 0) // if width is defined, it is setted
	{
		button->setScaleX(width / buttonWidth);
		buttonPosScaleWidth = width;
	}
	else // otherwise, we will compare the text width with the button width
	{
		float textWidth = pLabel->boundingBox().size.width;
		if (textWidth * 1.25 > buttonWidth) // if the width adapted to the text is bigger than the button width, adapted width must be setted, otherwise, button width must stay as it was
		{
			button->setScaleX(textWidth * 1.25f / buttonWidth);
			buttonPosScaleWidth = textWidth * 1.25f;
		}
	}
	
    // Place the label; must be in the center of the button
	pLabel->setPosition(ccp(buttonPosScaleWidth * 0.5f * 1/button->getScaleX(), buttonPosScaleHeight * 0.5f * 1/button->getScaleY()));
	
	// Set label centered anchor
	pLabel->setAnchorPoint(ccp(Constants::getAnchorValue(Centered), Constants::getAnchorValue(Middle)));
	
	// Add label to button
	button->addChild(pLabel);

	// Set label scale; the inverse of button scale, so label can be as it would be if it was a child of scene
	pLabel->setScaleY(1/button->getScaleY());
	pLabel->setScaleX(1/button->getScaleX());

	// If label is larger than button
	if (pLabel->boundingBox().size.width * button->getScaleX() > button->boundingBox().size.width)
	{
		// Label must be rescaled
		float newScale = button->boundingBox().size.width / (pLabel->boundingBox().size.width * button->getScaleX());
		pLabel->setScaleX(pLabel->getScaleX() * newScale);
	}

	// Add button to the menu
	menu->addChild(button, zOrder);
	
	return button;
}
开发者ID:Cnotinfor,项目名称:TopQX_2D,代码行数:90,代码来源:Objects2dFactory.cpp

示例8: ccp

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

	CCSize size = CCDirector::sharedDirector()->getWinSize();    
	CCUserDefault*handler=CCUserDefault::sharedUserDefault();
	issound=handler->getBoolForKey("issound",true);
	//playaudio=new PlayAudio();
	 
	//	playaudio->bgSound();
	
	 
	
	CCSprite* bg = CCSprite::create("ui/menubg.jpg");
	 
	bg->setPosition( ccp(size.width/2, size.height/2) );
	this->addChild(bg, 0,0);
 //logo
	CCSprite*logo=CCSprite::create("ui/logo.png");
	logo->setAnchorPoint(ccp(0.5,0.5));
	this->addChild(logo,3);
	logo->setPosition(ccp(360,920));
	 
	//³õʼ»¯°´Å¥
	CCMenuItemImage *newGameItem = CCMenuItemImage::create("ui/start1.png", "ui/start2.png.png",this,menu_selector(GameMenuScene::menuNewGameCallback));
	//newGameItem->setScale(0.5);
	newGameItem->setPosition(ccp(size.width / 2,size.height / 2 - 20));
	//newGameItem->setEnabled(false);
	CCMenuItemImage *continueItem = CCMenuItemImage::create("ui/score1.png", "ui/score2.png",this,menu_selector(GameMenuScene::menuScoreCallback));
	//continueItem->setScale(0.5);
	continueItem->setPosition(ccp(size.width / 2,size.height / 2 - 195));
	//continueItem->setEnabled(false);
	CCMenuItemImage *aboutItem = CCMenuItemImage::create("ui/about1.png", "ui/about2.png",this,menu_selector(GameMenuScene::menuScoreCallback));
	//aboutItem->setScale(0.5);
	aboutItem->setPosition(ccp(size.width / 2,size.height / 2 - 280));
//	aboutItem->setEnabled(false);
	soundItem = CCMenuItemImage::create("ui/ound1.png", "ui/sound2.png",this,menu_selector(GameMenuScene::menuSoundCallback));
	//soundItem->setScale(0.5);
	soundItem->setEnabled(true);
	soundItem->setPosition(ccp(50,50));

	if(issound){
		soundItem->setNormalImage(CCSprite::create("ui/sound1.png"));
		//soundItem->setDisabledImage(CCSprite::create("sound1.png"));
	 	}else{
		soundItem->setNormalImage(CCSprite::create("ui/sound2.png"));
		//soundItem->setDisabledImage(CCSprite::create("sound2.png"));
		 	}

	quitItem = CCMenuItemImage::create("ui/back1.png", "ui/back2.png",this,menu_selector(GameMenuScene::menuQuitCallback));
	//soundItem->setScale(0.5);
	quitItem->setEnabled(false);
	quitItem->setPosition(ccp(670,50));

	CCMenu* mainmenu = CCMenu::create(newGameItem,continueItem,soundItem,quitItem,NULL);
	mainmenu->setPosition(ccp(0,0));
	this->addChild(mainmenu,1,3);

	issound = true;
	/*SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic("background.mp3");
	SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0.5);
	SimpleAudioEngine::sharedEngine()->playBackgroundMusic("background.mp3", true);
	*/


	 
	
//	 this->addChild(pNode);
	 CCMenuItemFont*menuitem1=CCMenuItemFont::create("menuitem1",
		 this,menu_selector(GameMenuScene::menu1CallBack));

	 menuitem1->setPosition(ccp(300,300));
	 CCMenu*tempmenu=CCMenu::create(menuitem1,NULL);
	 
	 this->addChild(tempmenu);

	return true;
}
开发者ID:Creativegame,项目名称:cocos2dx-SuperMario,代码行数:81,代码来源:GameMenuScene.cpp

示例9: CC_BREAK_IF

// on "init" you need to initialize your instance
bool RectWorld::init()
{
    bool bRet = false;
    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 *pPauseItem = CCMenuItemImage::itemFromNormalImage("pause.png","pause.png",this,menu_selector(RectWorld::menuPause));
		CC_BREAK_IF(! pPauseItem);

		// Place the menu item bottom-right conner.
		pPauseItem->setPosition(ccp(22, 22));
		// Create a menu with the "close" menu item, it's an auto release object.
		CCMenu* pMenu = CCMenu::menuWithItems(pPauseItem, NULL);
		pMenu->setPosition(CCPointZero);
		pMenu->setTag(6);
		CC_BREAK_IF(! pMenu);

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

        // Create a "close" menu item with close icon, it's an auto release object.

        // Create a menu with the "close" menu item, it's an auto release object.

        // Get window size and place the label upper. 
        CCSize size = CCDirector::sharedDirector()->getWinSize();

        // 3. Add add a splash screen, show the cocos2d splash image.

        // Place the sprite on the center of the screen

		MovingBackground *bk = MovingBackground::node();

		this->addChild(bk);


		//CCParticleSystem *particle = ARCH_OPTIMAL_PARTICLE_SYSTEM::particleWithFile("tile.plist");

		//particle->setPosition(ccp(_player->getContentSize().width / 2 + size.width / 5 * 3, size.height / 2));

		//this->addChild(particle, 1);

		//this->schedule(schedule_selector(RectWorld::collision));
		this->schedule(schedule_selector(RectWorld::gameLogic), 1.0);
		this->schedule(schedule_selector(RectWorld::update));
		

		//CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this,0,true);

		if (_type == 3)
		{
			TimeLayer *timeLayer = TimeLayer :: node();
			timeLayer->setInitalTime(60);
			timeLayer->setTag(4);
			this->addChild(timeLayer, 3);

			this->schedule(schedule_selector(RectWorld::clockPassBy), 1.0f);
		}

        bRet = true;
    } while (0);

    return bRet;
}
开发者ID:sbhhbs,项目名称:FlyingCat,代码行数:77,代码来源:RectWorld.cpp

示例10: CC_BREAK_IF

bool BuyLifeLayer::init()
{
    bool bRet = false;

    do
    {
        CC_BREAK_IF (!CCLayer::init());
		CCSprite *p = CCSprite::create(g_sPanelBGImage);
		CCSize ps = p->getContentSize();

        
		CCSize s = CCDirector::sharedDirector()->getWinSize();
		CCScale9Sprite * bg = CCScale9Sprite::create(g_sPanelBGImage,CCRectMake(0,0,ps.width,ps.height),CCRectMake(20,20,ps.width-40,ps.height-40));
		this->addChild(bg);
		bg->setAnchorPoint(ccp(0,0));
		bg->setPreferredSize(CCSizeMake(s.width,s.height-beginY));
		this->setTouchEnabled(true);
		this->setTouchPriority(-999);

		p = CCSprite::create(g_sPanelBGImage2);
		ps = p->getContentSize();
		bg = CCScale9Sprite::create(g_sPanelBGImage2,CCRectMake(0,0,ps.width,ps.height),CCRectMake(20,20,ps.width-40,ps.height-40));
		this->addChild(bg);
		bg->setAnchorPoint(ccp(0,0));
		bg->setPreferredSize(CCSizeMake(s.width-20,s.height-20-beginY));
		bg->setPositionX(10);
		bg->setPositionY(10);

		CCMenuItemImage * back = CCMenuItemImage::create(g_sBackButtonUpBGImage,g_sBackButtonDownBGImage,
														this, 
														menu_selector(BuyLifeLayer::onCommandBack));
		back->setAnchorPoint(ccp(0,1));

		MyCCMenu * backMenu = MyCCMenu::create(back,NULL);
		this->addChild(backMenu);
		backMenu->setPositionX(28);
		backMenu->setPositionY(1000-beginY);
		backMenu->setTouchPriority(-1000);

		CCSprite * t2 = CCSprite::create(g_sBigLifeBGImage);
		t2->setAnchorPoint(ccp(0,1));
		t2->setPosition(ccp(82,890-beginY));
		this->addChild(t2);

		CCSprite * price2 = CCSprite::create(g_sBuy2BGImage);
		price2->setAnchorPoint(ccp(0,1));
		price2->setPosition(ccp(157,889-beginY));
		this->addChild(price2);

		CCSprite * coin2 = CCSprite::create(g_sGoldBGImage);
		coin2->setAnchorPoint(ccp(0,1));
		coin2->setPosition(ccp(392,891-beginY));
		this->addChild(coin2);

		CCMenuItemImage * buy2 = CCMenuItemImage::create(g_sOkButtonUpBGImage,g_sOkButtonDownBGImage,
														this, 
														menu_selector(BuyLifeLayer::onCommandBuy2));
		buy2->setAnchorPoint(ccp(0,1));
		MyCCMenu * buy2Menu = MyCCMenu::create(buy2,NULL);
		this->addChild(buy2Menu);
		buy2Menu->setPositionX(534);
		buy2Menu->setPositionY(907-beginY);
		buy2Menu->setTouchPriority(-1000);

		CCSprite * t5 = CCSprite::create(g_sBigLifeBGImage);
		t5->setAnchorPoint(ccp(0,1));
		t5->setPosition(ccp(82,719-beginY));
		this->addChild(t5);

		CCSprite * price5 = CCSprite::create(g_sBuy5BGImage);
		price5->setAnchorPoint(ccp(0,1));
		price5->setPosition(ccp(157,718-beginY));
		this->addChild(price5);

		CCSprite * coin5 = CCSprite::create(g_sGoldBGImage);
		coin5->setAnchorPoint(ccp(0,1));
		coin5->setPosition(ccp(392,723-beginY));
		this->addChild(coin5);

		CCMenuItemImage * buy5 = CCMenuItemImage::create(g_sOkButtonUpBGImage,g_sOkButtonDownBGImage,
														this, 
														menu_selector(BuyLifeLayer::onCommandBuy5));
		buy5->setAnchorPoint(ccp(0,1));
		MyCCMenu * buy5Menu = MyCCMenu::create(buy5,NULL);
		this->addChild(buy5Menu);
		buy5Menu->setPositionX(534);
		buy5Menu->setPositionY(736-beginY);
		buy5Menu->setTouchPriority(-1000);

		CCSprite * t21 = CCSprite::create(g_sBigLifeBGImage);
		t21->setAnchorPoint(ccp(0,1));
		t21->setPosition(ccp(82,550-beginY));
		this->addChild(t21);

		CCSprite * price21 = CCSprite::create(g_sBuy21BGImage);
		price21->setAnchorPoint(ccp(0,1));
		price21->setPosition(ccp(152,550-beginY));
		this->addChild(price21);

		CCSprite * coin21 = CCSprite::create(g_sGoldBGImage);
//.........这里部分代码省略.........
开发者ID:zhulu-mike,项目名称:CrazyStar,代码行数:101,代码来源:BuyLifeLayer.cpp

示例11: CC_BREAK_IF

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

		CC_BREAK_IF(! CCLayerColor::initWithColor( ccc4(255,255,255,255) ) );

		//////////////////////////////////////////////////////////////////////////
		// 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 *pCloseItem = CCMenuItemImage::create(
			"CloseNormal.png",
			"CloseSelected.png",
			this,
			menu_selector(HelloWorld::menuCloseCallback));
		CC_BREAK_IF(! pCloseItem);
        
		// Place the menu item bottom-right conner.
        CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
        CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
        
		pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2,
                                    origin.y + pCloseItem->getContentSize().height/2));

		// 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 your codes below...
		CCSprite *player = CCSprite::create("Player.png", CCRectMake(0, 0, 27, 40) );
        
		player->setPosition( ccp(origin.x + player->getContentSize().width/2,
                                 origin.y + visibleSize.height/2) );
		this->addChild(player);

		this->schedule( schedule_selector(HelloWorld::gameLogic), 1.0 );

		this->setTouchEnabled(true);

		_targets = new CCArray;
		_projectiles = new CCArray;

		// use updateGame instead of update, otherwise it will conflit with SelectorProtocol::update
		// see http://www.cocos2d-x.org/boards/6/topics/1478
		this->schedule( schedule_selector(HelloWorld::updateGame) );

		CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("background-music-aac.wav", true);

		bRet = true;
	} while (0);

	return bRet;
}
开发者ID:0309,项目名称:cocos2d-x,代码行数:67,代码来源:HelloWorldScene.cpp

示例12: ccp

bool GameMenu::init()
{
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCSize size = CCDirector::sharedDirector()->getWinSize();    

    //初始化背景
    CCSprite* bg = CCSprite::create("bg.png");
    bg->setScale(0.5);
    bg->setPosition( ccp(size.width/2, size.height/2) );
    this->addChild(bg, 0,0);
    //初始化背景星球
    CCSprite*bgstar = CCSprite::create("moon.png");
    bgstar->setAnchorPoint(ccp(0.5,0));
    bgstar->setScale(0.5);
    bgstar->setPosition(ccp(size.width/3 * 2, 0));
    this->addChild(bgstar,1,1);
    //初始化标题
    CCNode *title = CCNode::create();
    title->setContentSize(CCSizeMake(size.width - 40,50));
    CCSprite *ptmLabel = CCSprite::create("meowstar.png");
    ptmLabel->setScale(0.5);
    ptmLabel->setPosition( ccp(0,30) );
    title->addChild(ptmLabel);
    CCSprite *ptbLabel = CCSprite::create("battle.png");
    ptbLabel->setScale(0.5);
    ptbLabel->setPosition( ccp(0,-30) );
    title->addChild(ptbLabel);
    title->setPosition(ccp(size.width / 2, size.height - 80));
    this->addChild(title,2,2);
    //初始化按钮
    CCMenuItemImage *newGameItem = CCMenuItemImage::create("newGameA.png", "newGameB.png",this,menu_selector(GameMenu::menuNewGameCallback));
    newGameItem->setScale(0.5);
    newGameItem->setPosition(ccp(size.width / 2,size.height / 2 - 20));
    newGameItem->setEnabled(false);
    CCMenuItemImage *continueItem = CCMenuItemImage::create("continueA.png", "continueB.png",this,menu_selector(GameMenu::menuContinueCallback));
    continueItem->setScale(0.5);
    continueItem->setPosition(ccp(size.width / 2,size.height / 2 - 80));
    continueItem->setEnabled(false);
    CCMenuItemImage *aboutItem = CCMenuItemImage::create("aboutA.png", "aboutB.png",this,menu_selector(GameMenu::menuAboutCallback));
    aboutItem->setScale(0.5);
    aboutItem->setPosition(ccp(size.width / 2,size.height / 2 - 140));
    aboutItem->setEnabled(false);
    soundItem = CCMenuItemImage::create("sound-on-A.png", "sound-on-B.png",this,menu_selector(GameMenu::menuSoundCallback));
    soundItem->setScale(0.5);
    soundItem->setEnabled(false);
    soundItem->setPosition(ccp(40,40));
    //使用按钮创建菜单
    CCMenu* mainmenu = CCMenu::create(newGameItem,continueItem,aboutItem,soundItem,NULL);
    mainmenu->setPosition(ccp(0,0));
    this->addChild(mainmenu,1,3);
    //初始化声音部分
    issound = true;//是否开启声音参数
    SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic( CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("background.mp3") );
    SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0.5);
    SimpleAudioEngine::sharedEngine()->playBackgroundMusic(std::string(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("background.mp3")).c_str(), true);
    return true;
}
开发者ID:JoeHu,项目名称:book-code,代码行数:61,代码来源:GameMenuScene.cpp

示例13: 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...
		//////////////////////////////////////////////////////////////////////////

		CC_BREAK_IF(! CCLayerColor::initWithColor(ccc4(255, 255, 255, 255)));


		// 1. Add a menu item with "X" image, which is clicked to quit the program.
		//Background
		CCSize size = CCDirector::sharedDirector()->getWinSize();
		CCSprite *backgroud = CCSprite::create("MainMenu.png");
		CC_BREAK_IF(! backgroud);

		backgroud->setPosition(ccp(size.width / 2, size.height / 2));
		this->addChild(backgroud);
		// 2. Add a label shows "Hello World".

		// Create a label and initialize with string "Hello World".
// 		const char *title = "俄罗斯方块";
// 		const char *startGame = "开始游戏";
// 		const char *gameSet = "游戏设置";
// 		const char *score = "游戏得分";
// 		const char *gameOver = "游戏结束";

/*		const char *title = "TetrisGame";*/
// 		const char *startGame = "startGame";
// 		const char *gameSet = "gameSet";
// 		const char *score = "score";
// 		const char *gameOver = "gameEnd";

// 		CCLabelTTF* pLabel = CCLabelTTF::create(title, "Arial", 36);
// 		CC_BREAK_IF(! pLabel);
// 
// 		// Get window size and place the label upper. 
// 		pLabel->setPosition(ccp(size.width / 2, size.height * 4 / 5));
// 
// 		pLabel->setColor(ccc3(255, 255, 255));
// 		// Add the label to HelloWorld layer as a child layer.
// 		this->addChild(pLabel, 1);


		// 加入4个行走方向的控制菜单
// 		CCMenuItem *first = CCMenuItemFont::create(startGame, this, menu_selector(HelloWorld::menuCallbackStart));
// 		CCMenuItem *second = CCMenuItemFont::create(gameSet, this, menu_selector(HelloWorld::menuCallbackSet));
// 		CCMenuItem *third = CCMenuItemFont::create(score, this, menu_selector(HelloWorld::menuCallbackScore));
// 		CCMenuItem *forth = CCMenuItemFont::create(gameOver, this, menu_selector(HelloWorld::menuCallbackEnd));


// 		CCMenu *menu = CCMenu::create(first, second, third, forth, NULL);
// 		menu->setColor(ccc3(255, 255, 255));
		// 为了查找方便,给菜单项设置tag
		//down->setTag(kDown);
		//left->setTag(kLeft);
		//right->setTag(kRight);
		//up->setTag(kUp);
		// 菜单项按间距垂直排列
// 		menu->alignItemsVerticallyWithPadding(50);
// 		this->addChild(menu

		CCMenuItemImage *play = CCMenuItemImage::create(
			"play.png", 
			"play.png",
			this,
			menu_selector(HelloWorld::menuCallbackStart));
		play->setAnchorPoint(ccp(0, 0));
		play->setPosition(ccp(size.width / 4, (size.height * 2) / 5));
		

		CCMenuItemImage *end = CCMenuItemImage::create(
			"end.png", 
			"end.png",
			this,
			menu_selector(HelloWorld::menuCallbackEnd));
		end->setAnchorPoint(ccp(0, 0));
		end->setPosition(ccp(size.width / 4, (size.height * 2) / 7));

		CCMenu *menu = CCMenu::create(play, end, NULL);
		menu->setAnchorPoint(ccp(0, 0));
		menu->setPosition(ccp(0, 0));
		this->addChild(menu);


		bRet = true;
	} while (0);

	return bRet;
}
开发者ID:kidchen2012,项目名称:cocos2dx,代码行数:99,代码来源:HelloWorldScene.cpp

示例14: sprintf

bool Combat::init(int monsterType)
{
	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
  
  // Switch BGM
  AudioPlayer::PlayCombatBGM();
  
	//角色创建
	cplayer = CPlayer::create();
	cplayer->setPlayer();
	this->addChild(cplayer);
	monster = Monster::create();
	monster->setMonster(monsterType);


	this->addChild(monster);
	//血条创建
	playerblood = Blood::create();
	playerblood->setBloodSlider();
	playerblood->setSliderPosition(ccp(150,visibleSize.height-50));
	playerblood->setTotalBlood(cplayer->healthPoint);
	playerblood->setCurrentBlood(cplayer->currentHp);	
	monsterblood = Blood::create();
	monsterblood->setBloodSlider();
	monsterblood->setSliderPosition(ccp(visibleSize.width-150,visibleSize.height-50));
	monsterblood->setTotalBlood(monster->healthPoint);
	monsterblood->setCurrentBlood(monster->currentHp);
	this->addChild(playerblood);
	this->addChild(monsterblood);

	//等级与当前血量label
	/*等级*/
	char level[10],blood[10];
	sprintf(level,LEVEL_LBL,cplayer->level);
	plevelLabel = CCLabelTTF::create(level, LABEL_FONT,20);
	plevelLabel->setPosition(ccp(60,visibleSize.height-20));
	this->addChild(plevelLabel,2);
	sprintf(level,LEVEL_LBL,monster->level);
	mlevelLabel = CCLabelTTF::create(level, LEVEL_LBL,20);
	mlevelLabel->setPosition(ccp(visibleSize.width-60,visibleSize.height-20));
	this->addChild(mlevelLabel,2);
	/*血量*/
	sprintf(blood,HEALTH_LBL,cplayer->currentHp);
	pbloodLabel = CCLabelTTF::create(blood,LABEL_FONT,20);
	pbloodLabel->setPosition(ccp(240,visibleSize.height-20));
	this->addChild(pbloodLabel,2);
	sprintf(blood,HEALTH_LBL,monster->currentHp);
	mbloodLabel = CCLabelTTF::create(blood,LABEL_FONT,20);
	mbloodLabel->setPosition(ccp(visibleSize.width-240,visibleSize.height-20));
	this->addChild(mbloodLabel,2);



	//按钮创建
	playerbutton = AbilityButton::create();
	monsterbutton = AbilityButton::create();
	playerbutton->CreateButton();
	playerbutton->setButtonPosition(ccp(50,50));
	playerbutton->updateDamage(cplayer->level);
	monsterbutton->CreateButton();
	monsterbutton->setButtonPosition(ccp(480,50));
	monsterbutton->LockButtonTouch();
	monsterbutton->updateDamage(monster->level);

	if (monsterType==0)
	{
		CCMenuItemImage *pCloseItem = CCMenuItemImage::create(RUN_BTN_IMG_PATH,RUN_DOWN_BTN_IMG_PATH,this,menu_selector(Combat::exitCombat));
		pCloseItem->setPosition(ccp(visibleSize.width/2,50));
		CCMenu* pMenu = CCMenu::create(pCloseItem,NULL);
		pMenu->setPosition(CCPointZero);
		this->addChild(pMenu);
	}

	this->addChild(playerbutton);
	this->addChild(monsterbutton);

	//游戏结束Label
	winLabel = CCLabelTTF::create(YOU_WIN_LBL, LABEL_FONT, 80);
	loseLabel = CCLabelTTF::create(YOU_LOSE_LBL, LABEL_FONT, 80);
	winLabel->setPosition(ccp(visibleSize.width/2-20,visibleSize.height/2+20));
	loseLabel->setPosition(ccp(visibleSize.width/2-20,visibleSize.height/2+20));
	winLabel->setVisible(false);
	loseLabel->setVisible(false);
	this->addChild(winLabel);
	this->addChild(loseLabel);

	//schedule监听,每帧刷新一次
	this->scheduleUpdate();

	//订阅播放动画的消息
	CCNotificationCenter::sharedNotificationCenter()->addObserver(this,callfuncO_selector(Combat::playAnimation),ANIMATION_MSG,NULL);
	//订阅游戏结束
	CCNotificationCenter::sharedNotificationCenter()->addObserver(this,callfuncO_selector(Combat::gameOver),GAME_OVER_MSG,NULL);

	return true;
}
开发者ID:davidxk,项目名称:Blow-My-Lake,代码行数:97,代码来源:CombatScene.cpp

示例15: addChild

TanSuoLayer::TanSuoLayer()
{
	m_nFontSize = 24;
	m_nMaxCountDestroy = 3;
	m_bIsJieFeng = false;
	m_nSelectProId = -1;
	mBg = BaseSprite::create("xunbao_bg.png");
	addChild(mBg);
	mBg->setPosition(ccp(mWinSize.width/2, mBg->getContentSize().height/2));
	mMainMenu = CCMenu::create();
	mBg->addChild(mMainMenu, 10);
	mMainMenu->setPosition(ccp(0,0));
	CCMenuItemImage *yijian = CCMenuItemImage::create(
		"xunbao_anniu_yijianxunbao.png",
		"xunbao_anniu_yijianxunbao_select.png",
		this, menu_selector(TanSuoLayer::menuItemClicked_TanSuo));
	mMainMenu->addChild(yijian, 0, Tag_MenuItem_YiJianTanSuo);
	yijian->setPosition(ccp(548,mBg->getContentSize().height-674));

	Button *tansuo = Button::create();
	tansuo->loadTextures("xunbao_anniu_xunbao.png","xunbao_anniu_xunbao_select.png","xunbao_anniu_xunbao_select.png",UI_TEX_TYPE_LOCAL);
	/*CCMenuItemImage *tansuo = CCMenuItemImage::create(
		"xunbao_anniu_xunbao.png",
		"xunbao_anniu_xunbao_select.png",
		this, menu_selector(TanSuoLayer::menuItemClicked_TanSuo));*/
	tansuo->addTouchEventListener(this,SEL_TouchEvent(&TanSuoLayer::clickXunBao));

	


	UILayer* layer = UILayer::create();
	layer->ignoreAnchorPointForPosition(false);
	layer->setContentSize(tansuo->getContentSize());
	layer->setAnchorPoint(ccp(0.5,0.5));
	layer->addWidget(tansuo);
	layer->setPosition(320,mBg->getContentSize().height-674);//以前cpp(x,y) 现在左边 都是Point  比如颜色 ccWHITE 也改成了Color3B::WHITE
	mBg->addChild(layer);
	tansuo->setPosition(ccp(tansuo->getContentSize().width / 2 , tansuo->getContentSize().height / 2));

	m_sXunBaoSpr = CCSprite::create("xunbao_anniu_xunbao_xiaoguo.png");
	m_sXunBaoSpr->setPosition(ccp(320,mBg->getContentSize().height-674));
	mBg->addChild(m_sXunBaoSpr);
	m_sXunBaoSpr->runAction(CCRepeatForever::create(CCSequence::create(CCFadeOut::create(1.0f),CCFadeIn::create(1.0f),NULL)));
	//mMainMenu->addChild(tansuo, 0, Tag_MenuItem_TanSuo);
	//tansuo->setPosition(ccp(320,mBg->getContentSize().height-674));
	{
		CCMenuItemImage *jiefen = CCMenuItemImage::create(
			"xunbao_anniu_jiechufengyin.png",
			"xunbao_anniu_jiechufengyin_select.png",
			this, menu_selector(TanSuoLayer::menuItemClicked_TanSuo));
		mMainMenu->addChild(jiefen, 0, Tag_MenuItem_JieFen);
		jiefen->setPosition(ccp(320,mBg->getContentSize().height-437));
		jiefen->setVisible(false);
		CCSprite *img = CCSprite::create("xunbao_anniu_jiechufengyin_xiaoguo.png");
		jiefen->addChild(img);
		img->setPosition(ccp(jiefen->getContentSize().width/2, jiefen->getContentSize().height/2));
		img->runAction(CCRepeatForever::create(CCSequence::create(
			CCFadeTo::create(1, 50), CCFadeTo::create(1, 255), NULL)));
	}
	mMainMenu->setVisible(false);

	//title
	CCLabelTTF *tilte = CCLabelTTF::create(LFStrings::getValue("XunBaoShuoMing").c_str(), fontStr_kaiti, m_nFontSize);
	mBg->addChild(tilte);
	tilte->setColor(fonColor_PuTong);
	tilte->setPosition(ccp(mBg->getContentSize().width/2, mBg->getContentSize().height-110));
	//2
	CCLabelTTF *la1 = CCLabelTTF::create(LFStrings::getValue("XunBaoJieFeng").c_str(), fontStr_kaiti, m_nFontSize);
	mBg->addChild(la1);
	la1->setAnchorPoint(ccp(0, 0.5));
	la1->setColor(fonColor_CiYao);
	la1->setPosition(ccp(134, mBg->getContentSize().height-140));
	CCLabelTTF *la2 = CCLabelTTF::create((LFStrings::getValue("shenbing")+LFStrings::getValue("zhuangbei")).c_str()
		, fontStr_kaiti, m_nFontSize);
	la1->addChild(la2);
	la2->setColor(ImageManager::getManager()->getShowColor(ZhuangbeiColour_Chuanqi, false, false));
	la2->setPosition(ccp(la1->getContentSize().width+la2->getContentSize().width/2, la1->getContentSize().height/2));
	la1->setPositionX((mBg->getContentSize().width-la1->getContentSize().width-la2->getContentSize().width)/2);

}
开发者ID:longguai,项目名称:game-DarkWar,代码行数:80,代码来源:TanSuoLayer.cpp


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