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


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

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


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

示例1: initButton

void MarketScene::initButton()
{
	CCMenuItemImage *pMenuItem = CCMenuItemImage::create(s_pMenuItemBack.charMapFile, s_pMenuItemBack.charMapFilePress, this, menu_selector(MarketScene::buttonCallback));
	if (NULL != pMenuItem)
	{
		pMenuItem->setAnchorPoint(ccp(1,1));
		pMenuItem->setPosition(SCREEN);
		pMenuItem->setTag(BTN_CLOSE);
	}
	CCMenu *pMenu = CCMenu::create(pMenuItem, NULL);
	if (NULL != pMenu)
	{
		pMenu->setPosition(CCPointZero);
		addChild(pMenu);
		pMenu->setTag(TAG_MENU);
	}

	pMenuItem = CCMenuItemImage::create(s_pMenuItemBuy.charMapFile, s_pMenuItemBuy.charMapFilePress, s_pBuyDisable, this, menu_selector(MarketScene::buttonCallback));
	pMenuItem->setAnchorPoint(ccp(0.5f, 0.5f));
	pMenuItem->setPosition(ccp(CENTER.x, 120));
	pMenuItem->setTag(BTN_BUY);
	pMenu->addChild(pMenuItem);

	char szFileName[32] = { 0 };
	char szFileName2[32] = { 0 };
	char szFileName3[32] = { 0 };
	for (int i = 0; i < CARD_COUNT; i++)
	{
		sprintf(szFileName, s_pathCard.charMapFile, i);
		sprintf(szFileName2, s_pathCard.charMapFilePress, i);
		sprintf(szFileName3, s_pathCardDisable, i);

		CCMenuItemImage *pItem0 = CCMenuItemImage::create(szFileName, szFileName2, szFileName3);
		CCMenuItemImage *pItem1 = CCMenuItemImage::create(szFileName2, szFileName);
		CCMenuItemToggle *pToggle = CCMenuItemToggle::createWithTarget(this, menu_selector(MarketScene::buttonCallback), pItem0, pItem1, NULL);
		pToggle->setPosition(ccp(120 * i + s_pathCard.m_Position.x, s_pathCard.m_Position.y));
		pToggle->setTag(BTN_CARD + i);

		if (g_Control.cards[i] > 0)
		{
			CCSprite *sprite = CCSprite::create(s_pathCardbuy.m_strPath);
			sprite->setPosition(s_pathCardbuy.m_Position);
			pToggle->addChild(sprite, TAG_CARD_BUY, TAG_CARD_BUY);
		}

		pMenu->addChild(pToggle);
	}
	checkCard(BTN_CARD);
}
开发者ID:hyper123,项目名称:TurboSnail,代码行数:49,代码来源:MarketScene.cpp

示例2: buyCard

void MarketScene::buyCard(CCNode * pNode)
{
	int price = getPrice(selectedIndex);
	if (g_Control.m_nCoin >= price)
	{
		CCMenuItemImage *pItem = (CCMenuItemImage *)pNode;
		pItem->setEnabled(false);

		//¹´Ñ¡ÒÑÂòÏî
		CCMenu *pMenu = (CCMenu *)this->getChildByTag(TAG_MENU);
		CCMenuItemToggle *pToggle = (CCMenuItemToggle *)pMenu->getChildByTag(selectedIndex);
		CCSprite *sprite = CCSprite::create(s_pathCardbuy.m_strPath);
		sprite->setPosition(s_pathCardbuy.m_Position);
		pToggle->addChild(sprite, TAG_CARD_BUY, TAG_CARD_BUY);

		//¿ÛÇ®
		g_Control.m_nCoin -= price;
		updateLabelAtlas(g_Control.m_nCoin, LabelAtlas_COIN);

		g_Control.cards[selectedIndex - BTN_CARD] = 1;
		g_Control.save();
	}
}
开发者ID:hyper123,项目名称:TurboSnail,代码行数:23,代码来源:MarketScene.cpp


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