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


C++ CCMenuItemSprite::addChild方法代码示例

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


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

示例1: size

CCMenuItemSprite * CCMenuItemDynamic::dynamicItemWithText(const char* text,  const char* font, const CCSize &minSize,  const char*normalImage, const char *selectedImage, CCObject* target, SEL_MenuHandler selector, const CCRect& centerRegion, GLubyte opacity) {
	  //Create the label
	  CCLabelBMFont *label = CCLabelBMFont ::labelWithString(text ,font);
	  label ->setOpacity(opacity);

	  //Calculate the Dynamic Button size
	  float minWidth = label->getContentSize().width>minSize.width?label->getContentSize().width:minSize.width;
	  float minHeight = label->getContentSize().height>minSize.height?label->getContentSize().height:minSize.height;

	  CCSize size(minWidth+30,minHeight+24);

	  label->setPosition(ccp(size.width*0.5f, size.height*0.5f));

	  //Sprite normal
	  CCScale9Sprite *normalSprite = CCScale9Sprite::scale9SpriteWithFile(normalImage, centerRegion);	
	  normalSprite ->setContentSize(size);
	  normalSprite ->setOpacity(opacity);
	  //Sprite selected
	  CCScale9Sprite *selectedSprite = NULL;
	  if(selectedImage){
		  selectedSprite = CCScale9Sprite::scale9SpriteWithFile(selectedImage, centerRegion);	
		  selectedSprite ->setContentSize(size);
		  selectedSprite->setOpacity(opacity);
	  }

	  //Create the CCMenuItemSprite
	  CCMenuItemSprite* returnItem = CCMenuItemSprite::itemFromNormalSprite(normalSprite,selectedSprite,target, selector);
	  returnItem->addChild(label);
	  return returnItem;

}
开发者ID:jandujar,项目名称:zatacka-clone-cocos2d-x,代码行数:31,代码来源:CCMenuItemDynamic.cpp

示例2: getSpriteButton

CCMenuItemSprite* CCLayerParent::getSpriteButton(int tag,int price,const char* frameName,SEL_MenuHandler selector)
{	
 	CCSize winSize = CCDirector::sharedDirector()->getWinSize();

    CCMenuItemSprite *quirkButton =  CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("spawn.png"),CCSprite::createWithSpriteFrameName("spawn_sel.png"),this,selector);
    CCSize contentSize =  quirkButton->getContentSize();
	//quirkButton->setPosition (ccp(contentSize.width* tag, contentSize.height/2));
	quirkButton->setTag(tag);
    CCSprite* quirk = CCSprite::createWithSpriteFrameName(frameName);
	quirk->setPosition(ccp(quirk->getContentSize().width/2, contentSize.height-quirk->getContentSize().height/2));
    quirkButton->addChild(quirk);
    char temp[64];
    sprintf(temp, "%d", price);

    //CCLabel* quirkLabel = CCLabelBMFont::create(temp,"Courier_green.fnt");
	CCLabelTTF* quirkLabel = CCLabelTTF::create(temp, "Helvetica-Bold", fontSizeBig, ccp(xMARGIN,yMARGIN), kCCTextAlignmentCenter );
	quirkLabel->setColor(ccc3(255,255,255));
    quirkLabel->setPosition(ccp(quirk->getContentSize().width/2, yMARGIN*0.4));
    quirkButton->addChild(quirkLabel);
	quirkButton->setZOrder(3);
	return quirkButton;
}
开发者ID:lexshen,项目名称:WarCastleChipmunk,代码行数:22,代码来源:CCLayerParent.cpp

示例3: sprintf

CCMenuItemSprite *CWaterpump::initMenuItemWithFiles(int type, const char *normal, const char *selected, const char *disable, SEL_MenuHandler selector)
{
    CCSprite *pNormal = CCSprite::create(normal);
    CCSprite *pSelected = CCSprite::create(selected);
    CCSprite *pDisable = CCSprite::create(disable);

    CCMenuItemSprite *pItem = CCMenuItemSprite::create(pNormal, pSelected, pDisable, this, selector);
    int cnt = CPlayerAccount::GetAccountInstance()->GetAccountPropsNum(type);
    char szCntStr[8] = {0};
    sprintf(szCntStr, "%d", cnt);
    CCLabelAtlas *pCntFnt = CCLabelAtlas::create(szCntStr, "UI_02_05.png", 48, 57, '0');
    pCntFnt->setAnchorPoint(ccp(1, 0));
    pCntFnt->setPosition(ccp(pItem->getContentSize().width, 0));
    pItem->addChild(pCntFnt, 1, Tag_ItemFnt);
    pItem->setTag(type);
    return pItem;
}
开发者ID:gziproject,项目名称:DragonSlayer,代码行数:17,代码来源:Waterpump.cpp

示例4: glClearColor

Loading::Loading()
{
    glClearColor(0.0f/255.0f, 0.0f/255.0f, 0.0f/255.0f, 1.0f);
    setTouchEnabled( true );

    float scale = ScreenHelper::getTextureScale();
    float scaleX = ScreenHelper::getTextureScaleX();
    float scaleY = ScreenHelper::getTextureScaleY();
    
    CCTextureCache::sharedTextureCache()->addPVRImage("ctm_Buttons.pvr.ccz");
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ctm_Buttons.plist");
    
    CCTextureCache::sharedTextureCache()->addPVRImage("ctm_Icons.pvr.ccz");
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ctm_Icons.plist");
    
    CCTextureCache::sharedTextureCache()->addPVRImage("LoadingScreen.pvr.ccz");
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("LoadingScreen.plist");
    
    CCPoint scalePoint;
    scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER);
    scalePoint.y += -5*scale;
    CCSprite *sprite = CCSprite::createWithSpriteFrameName("ctm_Loading_Screen_ver2.png");
    sprite->setScale(scale);
    sprite->setPosition(scalePoint);
    addChild(sprite);
    
    
    sprite = CCSprite::createWithSpriteFrameName("ctm_Loading_ProgressScroll_Graphic.png");
    sprite->setScaleX(scaleX);
    sprite->setScaleY(scaleY*1.2f);
    sprite->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_LEFT,-140.0f,-50.0f));
    loadingBar = sprite;
    addChild(sprite,2);
    
    
    sprite = CCSprite::createWithSpriteFrameName("ctm_Loading_TopPanel.png");
    sprite->setScaleX(scaleX);
    sprite->setScaleY(scaleY);
    sprite->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,0.0f,-55.0f));
    addChild(sprite,2);
    
    sprite = CCSprite::createWithSpriteFrameName("ctm_Loading_TopOverlay.png");
    sprite->setScaleX(scaleX);
    sprite->setScaleY(scaleY);
    sprite->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER));
    addChild(sprite,2);
    
    sprite = CCSprite::createWithSpriteFrameName("BackgroundPlate.png");
    sprite->setScale(scale);
    scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER);
    scalePoint.x += -135.0f*scale;
    scalePoint.y += -97.0f*scale;
    sprite->setPosition(scalePoint);
    addChild(sprite,2);
    
    sprite = CCSprite::createWithSpriteFrameName("BronzeText.png");
    sprite->setScale(scale);
    scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER);
    scalePoint.x += -135.0f*scale;
    scalePoint.y += -97.0f*scale;
    sprite->setPosition(scalePoint);
    addChild(sprite,2);
    
    CCLabelTTF *label = CCLabelTTF::create(LevelSelect::getLevelName(), "impact.ttf", 42*scale);
    addChild(label, 2);
    label->setColor(ccc3(0,0,0));
    label->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,2.0f,-44.0f));
    
    label = CCLabelTTF::create(LevelSelect::getLevelName(), "impact.ttf", 42*scale);
    addChild(label, 2);
    label->setColor(ccc3(237,188,0));
    label->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,0.0f,-42.0f));
    
    int currentLevel = LevelSelect::getCurrentLevel();
    if(currentLevel >= BONUS_LEVELSTART)
        g_isTrickLevel = true;
    else
        g_isTrickLevel = false;
    
    
    int medalLevel = SaveLoad::m_SaveData.medalLockLevel;
    int showMedal = 0;
    if(medalLevel==0)
    {
        if(SaveLoad::m_SaveData.levelflags[currentLevel] & SaveLoad::ONE_COCONUT)
            showMedal = 1;
    }
    if(medalLevel==1)
    {
        if(SaveLoad::m_SaveData.levelflags[currentLevel] & SaveLoad::TWO_COCONUT)
            showMedal = 2;
    }
    if(medalLevel==2)
    {
        if(SaveLoad::m_SaveData.levelflags[currentLevel] & SaveLoad::THREE_COCONUT)
            showMedal = 3;
    }
    
    if(!showMedal)
    {
//.........这里部分代码省略.........
开发者ID:ryanmcbride,项目名称:CrashTestMonkeysDroid,代码行数:101,代码来源:Loading.cpp

示例5: init

// on "init" you need to initialize your instance
bool InGameTopMenuLayer::init() {
	if (!CCLayerColor::initWithColor(ccc4(255, 255, 255, 255)))
		return false;
	float scaleMult = Model::getInstance()->getGUIElementScaleMultiplicator();
	float button_length = 66 * scaleMult;
	float button_heigth = 66 * scaleMult;
	float padding = 10 * scaleMult;
	_soundOnString = "on";
	_soundOffString = "off";

	CCMenuItemSprite *shutdown = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("shutdown0.png"),
			CCSprite::createWithSpriteFrameName("shutdown1.png"), (CCObject*) this, menu_selector(InGameTopMenuLayer::shutdownTouched));
	shutdown->setScaleX(button_length / shutdown->getContentSize().width);
	shutdown->setScaleY(button_heigth / shutdown->getContentSize().height);

	CCMenuItemSprite *autoCam = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("autoCam0.png"),
			CCSprite::createWithSpriteFrameName("autoCam1.png"), (CCObject*) this, menu_selector(InGameTopMenuLayer::autoCamTouched));
	autoCam->setScaleX(button_length / autoCam->getContentSize().width);
	autoCam->setScaleY(button_heigth / autoCam->getContentSize().height);

	float scale = button_heigth / autoCam->getContentSize().height;
	_autCamOnOffLabel = CCLabelTTF::create("auto", FONT_NAME, PRICE_LABEL_FONT_SIZE / scale * scaleMult,
			CCSize(autoCam->getContentSize().width, PRICE_LABEL_HEIGTH / scale * scaleMult), kCCTextAlignmentCenter);
	autoCam->addChild(_autCamOnOffLabel);
	_autCamOnOffLabel->setColor(Model::getInstance()->getInGameGameLayer()->getAutoCam() ? ccc3(0, 255, 0) : ccc3(255, 0, 0));
	_autCamOnOffLabel->setPosition(CCPoint(autoCam->getContentSize().width / 2, PRICE_LABEL_BOTTOM_SPACE / scale * scaleMult));
	_autCamOnOffLabel->enableStroke(PRICE_LABEL_COLOR_STROKE, PRICE_LABEL_STROKE_SIZE / scale * scaleMult, true);

	CCMenuItemSprite *autoCamSwitch = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("autoCamSwitch0.png"),
			CCSprite::createWithSpriteFrameName("autoCamSwitch1.png"), (CCObject*) this, menu_selector(InGameTopMenuLayer::flipThisPlayerForCamTouched));
	autoCamSwitch->setScaleX(button_length / autoCamSwitch->getContentSize().width);
	autoCamSwitch->setScaleY(button_heigth / autoCamSwitch->getContentSize().height);

	CCMenuItemSprite *pause = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("pause1.png"), CCSprite::createWithSpriteFrameName("pause2.png"),
			(CCObject*) this, menu_selector(InGameTopMenuLayer::pauseTouched));
	pause->setScaleX(button_length / pause->getContentSize().width);
	pause->setScaleY(button_heigth / pause->getContentSize().height);

	CCMenuItemSprite *zoomIn = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("ZoomIn1.png"), CCSprite::createWithSpriteFrameName("ZoomIn2.png"),
			(CCObject*) this, menu_selector(InGameTopMenuLayer::zoomInTouched));
	zoomIn->setScaleX(button_length / zoomIn->getContentSize().width);
	zoomIn->setScaleY(button_heigth / zoomIn->getContentSize().height);

	CCMenuItemSprite *zoomOut = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("ZoomOut1.png"),
			CCSprite::createWithSpriteFrameName("ZoomOut2.png"), (CCObject*) this, menu_selector(InGameTopMenuLayer::zoomOutTouched));
	zoomOut->setScaleX(button_length / zoomOut->getContentSize().width);
	zoomOut->setScaleY(button_heigth / zoomOut->getContentSize().height);

	CCMenuItemSprite *toggleGUI = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("toggleGUI1.png"),
			CCSprite::createWithSpriteFrameName("toggleGUI2.png"), (CCObject*) this, menu_selector(InGameTopMenuLayer::toggleGUITouched));
	toggleGUI->setScaleX(button_length / toggleGUI->getContentSize().width);
	toggleGUI->setScaleY(button_heigth / toggleGUI->getContentSize().height);

	CCMenuItemSprite *enableSound = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("soundEnable0.png"),
			CCSprite::createWithSpriteFrameName("soundEnable1.png"), (CCObject*) this, menu_selector(InGameTopMenuLayer::enableSoundTouched));
	enableSound->setScaleX(button_length / enableSound->getContentSize().width);
	enableSound->setScaleY(button_heigth / enableSound->getContentSize().height);

	scale = button_heigth / enableSound->getContentSize().height;
	_enableSoundLabel = CCLabelTTF::create(SoundHandler::getInstance()->isSoundEnabled() ? _soundOnString.c_str() : _soundOffString.c_str(), FONT_NAME,
			PRICE_LABEL_FONT_SIZE / scale * scaleMult, CCSize(enableSound->getContentSize().width, PRICE_LABEL_HEIGTH / scale * scaleMult),
			kCCTextAlignmentCenter);
	enableSound->addChild(_enableSoundLabel);
	_enableSoundLabel->setColor(SoundHandler::getInstance()->isSoundEnabled() ? ccc3(0, 255, 0) : ccc3(255, 0, 0));
	_enableSoundLabel->setPosition(CCPoint(enableSound->getContentSize().width / 2, PRICE_LABEL_BOTTOM_SPACE / scale * scaleMult));
	_enableSoundLabel->enableStroke(PRICE_LABEL_COLOR_STROKE, PRICE_LABEL_STROKE_SIZE / scale * scaleMult, true);

	CCMenu* menu = CCMenu::create();
	int x = 0;
	int y = 1;
	ViewTools::addToMenu(menu, zoomIn, button_length, button_heigth, x++, y, padding);
	ViewTools::addToMenu(menu, zoomOut, button_length, button_heigth, x++, y, padding);
	ViewTools::addToMenu(menu, autoCamSwitch, button_length, button_heigth, x++, y, padding);
	ViewTools::addToMenu(menu, autoCam, button_length, button_heigth, x++, y, padding);
	ViewTools::addToMenu(menu, toggleGUI, button_length, button_heigth, x++, y, padding);

	if (Model::getInstance()->getGameMode() != NETWORK)
		ViewTools::addToMenu(menu, pause, button_length, button_heigth, x++, y, padding);

	ViewTools::addToMenu(menu, shutdown, button_length, button_heigth, x, y, padding);
	ViewTools::addToMenu(menu, enableSound, button_length, button_heigth, x, y - 1, padding);

	// resizing this layer to the menu and place the menu correct
	float width = (x + 1) * button_length + x * padding;

	float height = button_heigth * 2 + padding;
	setContentSize(CCSize(width, height));
	menu->setPosition(0, 0);
	addChild(menu);

	CCSize winSize = CCDirector::sharedDirector()->getWinSize();
	setPosition(winSize.width - width - (UNITS_INFO_OVERLAY_WIDTH * scaleMult), winSize.height - height);
	setOpacity(0); // 0- total transparent, 255 not
	return true;
}
开发者ID:Gwill,项目名称:BaseWar,代码行数:96,代码来源:InGameTopMenuLayer.cpp

示例6: init

bool MultiplayerLayer::init()
{
    bool bRet = false;
	do
	{
		CC_BREAK_IF(! OverlayBase::init());
		
		CCSize size = CCDirector::sharedDirector()->getWinSize();
		int leftSpace = 100;

        _opponentType = kHuman;
        
        CCMenuItemSprite* hItem = createMenuItemSprite((char*)"btnHotSeat128x128.png",
                                                       (char*)"btnHotSeatPressed.png",
                                                       menu_selector(MultiplayerLayer::onHotSeat));
        CCMenuItemSprite* onlineItem = createMenuItemSprite((char*)"btnOnlineGame128x128.png",
                                                       (char*)"btnOnlineGamePressed.png",
                                                       menu_selector(MultiplayerLayer::onOnlineGame));
        
        CCMenu* menu = CCMenu::create(hItem, onlineItem, NULL);
        menu->alignItemsVertically();
		menu->setPosition(ccp(leftSpace, size.height - 2 * leftSpace));
		addChild(menu, 1);
        
        
        if (!sgl_ConnectionManager.getRoomNumber().empty())
        {
            CCMenuItemSprite* onlineReconnectItem = createMenuItemSprite((char*)"btnOnlineGameReconnect.png",
                                                                (char*)"btnOnlineGamePressed.png",
                                                                menu_selector(MultiplayerLayer::onOnlineGame));
            
            menu->cocos2d::CCNode::addChild(onlineReconnectItem);
        }
        
		float menuLimit = hItem->getPosition().x + hItem->boundingBox().size.width + 20;

		CCLabelTTF* lH = new CCLabelTTF();
		lH->initWithString("Hot seat", S_F_TYPE.c_str(), 32);
		lH->setPosition(ccp(menuLimit, hItem->getPosition().y));
		lH->setAnchorPoint(ccp(0,0));
        hItem->addChild(lH);
        
        CCLabelTTF* lO = new CCLabelTTF();
        lO->initWithString("Random online game", S_F_TYPE.c_str(), 32);
        lO->setPosition(ccp(menuLimit, hItem->getPosition().y));
		lO->setAnchorPoint(ccp(0,0));
        onlineItem->addChild(lO);

        //Cancel - Go Menu
        CCMenuItemSprite* mRightArrow =
            sgl_SpriteFactory.createMenuItemSprite("btnArrow_Back128x128.png", "btnArrow_Back128x128Pressed.png", menu_selector(MultiplayerLayer::onQuit), this);
        CCMenu* menuReturn = CCMenu::create(mRightArrow, NULL);
        
        CCMenuItemSprite* mLeftArrow =
            sgl_SpriteFactory.createMenuItemSprite("btnArrow128x128.png", "btnArrow128x128Pressed.png", menu_selector(MultiplayerLayer::onConnect), this);
        
        CCMenu* mStartGame = CCMenu::create(mLeftArrow, NULL);
        
		menuReturn->setPosition(leftSpace, 150);
		mStartGame->setPosition(size.width - leftSpace - mLeftArrow->boundingBox().size.width * 0.5f, 150);
        
        addChild(mStartGame);
        addChild(menuReturn);
        
        
        _connectionStatus = CCLabelTTF::create("", S_F_TYPE.c_str(), 32);
		_connectionStatus->setPosition(ccp(size.width/2, 150));
        
        this->addChild(_connectionStatus);
        
		bRet = true;
	} while (0); 
    
	return bRet;
}
开发者ID:koboldul,项目名称:Football,代码行数:75,代码来源:MultiplayerLayer.cpp

示例7: adjustMap

void LevelMap::adjustMap(bool isResetLevel)
{
	int num = floor(offsetY/442);
	currentMap = -num;
	int offnum = num%3;
	float tmpoff = offsetY - num*442;
	mapLayer->setPosition(ccp(0, (offnum-1)*442 + tmpoff));

	if(isResetLevel)
	{
		int offlevel = 1000 + currentMap*3 -3;
		for (int i = 0; i < 9 ; i++)
		{
			MapItem* tmpLevelItemData = NULL;
			tmpLevelItemData = CData::getCData()->getConfigOfMapLevel(offlevel + i);

			CCMenuItemSprite* tmp = (CCMenuItemSprite*)levelSpDic->objectForKey(i);
			tmp->removeChildByTag(9999);

			if (tmpLevelItemData!= NULL && tmpLevelItemData->bid < currentLevelId)
			{
				CCSize tmpsz = tmp->getContentSize();
				CCSprite* ssp = CCSprite::create();

				int num = data["citylist"][tmpLevelItemData->bid - 1000].asInt();
				for (int k = 0; k<num; k++)
				{
					CCSprite * star = CCSprite::create("zjm_star.png");
					star->setPosition(ccp(k*30, 0));
					ssp->addChild(star);
				}
				ssp->setPosition(ccp(tmpsz.width/2-15*num+15, 0));
				ssp->setTag(9999);
				tmp->addChild(ssp, 0);
			}

			if(tmpLevelItemData != NULL)
			{
				if(tmpLevelItemData->bid > currentLevelId)
				{
					tmp->setEnabled(false);
				}
				else
				{
					tmp->setEnabled(true);
				}
				tmp->setUserObject(tmpLevelItemData);
			}

			//for (int j = 1001; j<=1005; j++)
			//{
			CCLabelTTF* tmpName = (CCLabelTTF*)(tmp->getChildByTag(1002));
			if(tmpLevelItemData)
			{
				tmpName->setString(tmpLevelItemData->nickname.c_str());
			}
			//}
		}
	}

	levelsMenu->setPosition(ccp(0, -442 + tmpoff));
}
开发者ID:cnsuperx,项目名称:Test,代码行数:62,代码来源:LevelMap.cpp

示例8: init

bool LevelMap::init()
{
    if(!CCLayer::init())
    {
        return false;
    }
    
    this->setTouchEnabled(true);
    
    levelSpDic = CCDictionary::create();
    levelSpDic->retain();
    
    currentMap = 0;
    size = CCDirector::sharedDirector()->getWinSize();
    
//    CCSprite* bkg = CCSprite::create("zjm_bkg.png");
//    bkg->setAnchorPoint(ccp(0, 0));
//    bkg->setPosition(ccp(0, 0));
//    this->addChild(bkg);
    
    mapLayer = CCSprite::create();
    
    CCSprite* m1 = CCSprite::create("map3.png");
    m1->setAnchorPoint(ccp(0, 0));
    m1->setPosition(ccp(0, 0));
    
    CCSprite* m2 = CCSprite::create("map1.png");
    m2->setAnchorPoint(ccp(0, 0));
    m2->setPosition(ccp(0, 441));
    
    CCSprite* m3 = CCSprite::create("map2.png");
    m3->setAnchorPoint(ccp(0, 0));
    m3->setPosition(ccp(0, 441*2));
    
    CCSprite* m4 = CCSprite::create("map3.png");
    m4->setAnchorPoint(ccp(0, 0));
    m4->setPosition(ccp(0, 441*3));
    
    CCSprite* m5 = CCSprite::create("map1.png");
    m5->setAnchorPoint(ccp(0, 0));
    m5->setPosition(ccp(0, 441*4));
   
    mapLayer->addChild(m1);
    mapLayer->addChild(m2);
    mapLayer->addChild(m3);
    mapLayer->addChild(m4);
    mapLayer->addChild(m5);
    mapLayer->setAnchorPoint(ccp(0, 0));
    mapLayer->setPosition(ccp(0, 0));
    
	// 将一个Layer添加到CCSprite里面
    mapSp = CCSprite::create();
    mapSp->addChild(mapLayer);
    mapSp->setAnchorPoint(ccp(0, 0));
    mapSp->setPosition(ccp(0, 0));
    this->addChild(mapSp);
    
    levelsMenu = CCMenu::create();
    levelsMenu->setAnchorPoint(ccp(0, 0));
    levelsMenu->setPosition(ccp(0, 0));
    this->addChild(levelsMenu);
    
    CCSprite* bkg = CCSprite::create("zjm_bkg.png");
    bkg->setAnchorPoint(ccp(0, 0));
    bkg->setPosition(ccp(0, 0));
    this->addChild(bkg);
    
    for (int i = 0; i < 9; i++)
    {
		// 地图上的选中框,并添加点击事件clkBuilding;
        CCMenuItemSprite* leveltmp = CCMenuItemImage::create("zjm_building_1.png", "zjm_building_1.png", "zjm_building_2.png",this, menu_selector(LevelMap::clkBuilding));
        int num = (int)floor((float)i/3);
        
        leveltmp->setPosition(ccp((i-3*num)%2==1?140:size.width-130, (130)*(i%3) + 442*(int)floor((float)i/3) +240));//160
        levelSpDic->setObject(leveltmp, i);
        levelsMenu->addChild(leveltmp);
        
        const ccColor3B color3 = {255,175,100};
        const ccColor3B colorbg = {255,175,51};
        
        CCSize tmpsz = leveltmp->getContentSize();
        CCLabelTTF * name11=CCLabelTTF::create("", "hycc.ttf", 20);
        name11->setDimensions(CCSizeMake(200, 0));
        name11->setHorizontalAlignment(kCCTextAlignmentCenter);
        name11->setVerticalAlignment(kCCVerticalTextAlignmentTop);
        name11->setPosition(ccp(tmpsz.width/2-1, 35));
        
        name11->setColor(colorbg);
//        leveltmp->addChild(name11);
        leveltmp->addChild(name11, 10);
        name11->setTag(1002);
    }
    
    char * json=CData::getCData()->cityData;
    Json::Reader read;
    Json::Value  root;
    
    if(read.parse(json, root))
    {
        data=root["data"];
//.........这里部分代码省略.........
开发者ID:cnsuperx,项目名称:Test,代码行数:101,代码来源:LevelMap.cpp

示例9: init

bool PrepareLayer::init()
{
	CCSize size = ToolsFun::sharedTools()->getSceneSize();
	//背景
	CCSprite *spBkg = CCSprite::create("ui/shared/bkg.png");
	this->addChild(spBkg,-1);
	spBkg->setPosition(size/2);

	//放置人物设定背景
	CCSprite *spBkgHero = CCSprite::create("ui/prepareUI/mainbkg.png");
	this->addChild(spBkgHero,-1);
	spBkgHero->setPosition(ccp(size.width/2,size.height - spBkgHero->getContentSize().height/2 - 50*gScaleY));

	//购物
	CCSprite *spBkgTop = CCSprite::create("ui/shared/top.png");
	this->addChild(spBkgTop,0,108);
	spBkgTop->setPosition(ccp(size.width/2,size.height - spBkgTop->getContentSize().height/2));

	//人物游戏记录背景
	CCSprite *spRecoreBkg = CCSprite::create("ui/prepareUI/recordbkg.png");
	this->addChild(spRecoreBkg,-1);
	spRecoreBkg->setPosition(ccp(315*gScaleX,600*gScaleY));
	//spRecoreBkg->setScale(PRE_SCALE);

	//宠物,道具背景
	for (int i=0;i!=1;++i)
	{
		CCSprite *sp = CCSprite::create("ui/shared/placeboard.png");
		this->addChild(sp,-1);
		sp->setPosition(ccp(size.width/4 + i * size.width/2,165*gScaleY));
		sp->setScale(1.10f);
	}

	int level = GameConfigData::initialGameData().getCurLevel();
	int killTotal = 0;

	killTotal = atoi( GameConfigData::initialGameData().getKillTotal().c_str());

	char buf[64];
	sprintf(buf,"%d",killTotal);

	int levelMaxStr = GameConfigData::initialGameData().getMaxUnLockLevel();
	string strs[4] = 
	{
		GameConfigData::initialGameData().getHScores(),
		GameConfigData::initialGameData().getHLenght(),
		string(buf),
		ToolsFun::sharedTools()->intToString(levelMaxStr)
	};

	for (int i=0;i!=4;++i)
	{
		CCLabelBMFont *hScores = CCLabelBMFont::create(strs[i].c_str() ,"font/white_30.fnt");
		spRecoreBkg->addChild(hScores);
		hScores->setPosition(ccp(150*gScaleX,(165-8-38*i))*gScaleY);
		hScores->setAnchorPoint(ccp(0,0.5f));
	}

	m_menu = CCMenu::create();
	this->addChild(m_menu,1);
	m_menu->setPosition(CCPointZero);

	//所有按钮的放置
	const char* fName[9] = 
	{
		"ui/shared/back.png",//返回
		"ui/shared/coinplus.png",//添加金币
		"ui/prepareUI/head.png",//主角头像
		"ui/prepareUI/upgrade.png",//升级按钮
		"ui/shared/shop_item.png",//宠物1
		"ui/shared/shop_item.png",//宠物2
		"ui/shared/shop_item.png",//道具1
		//	"ui/shared/shop_item.png",//道具2
		"ui/shared/confirm.png"//确定开始游戏
	};

	const CCPoint posArray[9] = 
	{
		ccp(37*gScaleX,size.height-37*gScaleY),ccp(430*gScaleX,size.height-30*gScaleY),ccp(290*gScaleX,435*gScaleY),ccp(360*gScaleX,335*gScaleY),
		ccp(54*gScaleX,145*gScaleY),ccp(144*gScaleX,145*gScaleY),ccp(355*gScaleX,145*gScaleY),ccp(235*gScaleX,40*gScaleY),ccp(235*gScaleX,40*gScaleY)
	};

	for (int i=0;i!=8;++i)
	{
		CCSprite *spNml = CCSprite::create(fName[i]);
		CCSprite *spSel = CCSprite::create(fName[i]);
		spSel->setColor(ccc3(80,80,80));
		CCMenuItemSprite *itemSp = CCMenuItemSprite::create(spNml,spSel,
			this,menu_selector(PrepareLayer::menuTouch));
		if(i==2)
		{
			m_menu->addChild(itemSp,1,100+i);
			itemSp->setPosition(posArray[i]);
			itemSp->setScale(0.8f);
		}
		else if(i ==3)
		{
			m_menu->addChild(itemSp,1,100+i);
			itemSp->setPosition(posArray[i]);
			itemSp->setScale(PRE_SCALE);
//.........这里部分代码省略.........
开发者ID:xuqin,项目名称:tgp,代码行数:101,代码来源:PrepareLayer.cpp

示例10: initPet

void PrepareLayer::initPet(int leftOrRight)
{
	///**初始化已经出战的左边的宠物**///
	int petId = -1;
	for (int i =0;i !=6; ++i )
	{
		if (GameConfigData::initialGameData().getPetStateById(i) == "2")
		{
			if (GameConfigData::initialGameData().getPetPosById(i) == leftOrRight)
			{
				petId = i;
			}
		}
	}

	CCMenuItemSprite *petAddLeft = (CCMenuItemSprite *)m_menu->getChildByTag(100+4+leftOrRight);
	if (petAddLeft->getChildByTag(1000))
	{
		petAddLeft->removeChildByTag(1000);
	}

	CCPoint leftPoint[6] = {petAddLeft->getContentSize()/2+ccp(20*gScaleX,0),petAddLeft->getContentSize()/2+ccp(20*gScaleX,0),petAddLeft->getContentSize()/2+ccp(30*gScaleX,0),
		petAddLeft->getContentSize()/2+ccp(30*gScaleX,0),petAddLeft->getContentSize()/2+ccp(30*gScaleX,0),petAddLeft->getContentSize()/2+ccp(30*gScaleX,0)};
	float scale[6] = {0.4*PRE_SCALE,0.4*PRE_SCALE,0.5*PRE_SCALE,0.5*PRE_SCALE,0.5*PRE_SCALE,0.5*PRE_SCALE};

	CCSprite *sp = NULL;
	if (petId != -1)
	{
		char petFile[48];
		sprintf(petFile,"ui/petUI/pet%d_0.png",petId);
		sp = CCSprite::create(petFile);
		sp->setScale(scale[petId]);
		if(leftOrRight ==0)
		{
			sp->setPosition(leftPoint[petId]);
			m_leftPitId = petId;
		}
		else
		{
			sp->setPosition(leftPoint[petId]);
			m_rightPetId  =petId;
		}

		showHeroPet(leftOrRight,petId);
	}
	else
	{
		sp = CCSprite::create("ui/shared/plus.png");	
		sp->setPosition(petAddLeft->getContentSize()/2+ccp(20*gScaleX,0));

		if(leftOrRight ==0)
		{
			if(this->getChildByTag(45456)!=NULL)
			{
				this->getChildByTag(45456)->setVisible(false);
			}
		}
		else
		{
			if(this->getChildByTag(45457)!=NULL)
			{
				this->getChildByTag(45457)->setVisible(false);
			}
		}
	}

	petAddLeft->addChild(sp,1,1000);
}
开发者ID:xuqin,项目名称:tgp,代码行数:68,代码来源:PrepareLayer.cpp


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