本文整理汇总了C++中CCNode::getComponent方法的典型用法代码示例。如果您正苦于以下问题:C++ CCNode::getComponent方法的具体用法?C++ CCNode::getComponent怎么用?C++ CCNode::getComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCNode
的用法示例。
在下文中一共展示了CCNode::getComponent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createGameScene
cocos2d::CCNode* SceneEditorTestLayer::createGameScene()
{
CCNode *pNode = CCJsonReader::sharedJsonReader()->createNodeWithJsonFile("FishJoy2.json");
if (pNode == NULL)
{
return NULL;
}
m_pCurNode = pNode;
//play back music
CCComAudio *pAudio = (CCComAudio*)(pNode->getComponent("Audio"));
pAudio->playBackgroundMusic(pAudio->getFile(), pAudio->getIsLoop());
//fishes
CCArmature *pBlowFish = getFish(5, "blowFish");
CCArmature *pButterFlyFish = getFish(6, "butterFlyFish");
pBlowFish->getAnimation()->playByIndex(0);
pButterFlyFish->getAnimation()->playByIndex(0);
CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", this, menu_selector(SceneEditorTestLayer::toExtensionsMainLayer));
itemBack->setColor(ccc3(255, 255, 255));
itemBack->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
CCMenu *menuBack = CCMenu::create(itemBack, NULL);
menuBack->setPosition(CCPointZero);
menuBack->setZOrder(4);
pNode->addChild(menuBack);
//ui action
cocos2d::extension::UIActionManager::shareManager()->PlayActionByName("startMenu_1.json","Animation1");
return pNode;
}
示例2: 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...
CCNode* gameScene = SceneReader::sharedSceneReader()->createNodeWithSceneFile("DemoCowboy.json");
addChild(gameScene);
//Create player
CCNode* playerNode = gameScene->getChildByTag(10004);
player = new Player(playerNode);
//Assign callbacks to the buttons
CCNode* uiNode = gameScene->getChildByTag(10005);
UILayer* ui = (UILayer*)uiNode->getComponent("GUIComponent")->getNode();
UIButton* btnLeft = (UIButton*)ui->getWidgetByName("LeftButton");
btnLeft->addTouchEventListener(this, toucheventselector(HelloWorld::onMoveLeft));
UIButton* btnRight = (UIButton*)ui->getWidgetByName("RightButton");
btnRight->addTouchEventListener(this, toucheventselector(HelloWorld::onMoveRight));
UIButton* btnFire = (UIButton*)ui->getWidgetByName("FireButton");
// btnFire->addReleaseEvent(this, coco_releaseselector(HelloWorld::onFire));
btnFire->addTouchEventListener(this, toucheventselector(HelloWorld::onFire));
//Enable update loop
this->scheduleUpdate();
return true;
}
示例3: removeAll
void ArmatureActionState::removeAll()
{
do
{
CCNode *pNode = SceneReader::sharedSceneReader()->getNodeByTag(_nTag);
CC_BREAK_IF(pNode == NULL);
CCComRender *pRender = (CCComRender*)(pNode->getComponent(_ComName.c_str()));
CC_BREAK_IF(pRender == NULL);
CCArmature *pAr = (CCArmature *)(pRender->getNode());
CC_BREAK_IF(pAr == NULL);
TriggerMng::sharedTriggerMng()->removeArmatureMovementCallBack(pAr, this, movementEvent_selector(ArmatureActionState::animationEvent));
} while (0);
}
示例4: done
void ArmaturePlayAction::done()
{
do
{
CCNode *pNode = SceneReader::sharedSceneReader()->getNodeByTag(_nTag);
CC_BREAK_IF(pNode == NULL);
CCComRender *pRender = (CCComRender*)(pNode->getComponent(_comName.c_str()));
CC_BREAK_IF(pRender == NULL);
CCArmature *pAr = (CCArmature *)(pRender->getNode());
CC_BREAK_IF(pAr == NULL);
pAr->getAnimation()->play(_aniname.c_str());
} while (0);
}
示例5: init
bool ArmatureActionState::init()
{
do
{
CCNode *pNode = SceneReader::sharedSceneReader()->getNodeByTag(_nTag);
CC_BREAK_IF(pNode == NULL);
CCComRender *pRender = (CCComRender*)(pNode->getComponent(_comName.c_str()));
CC_BREAK_IF(pRender == NULL);
CCArmature *pAr = (CCArmature *)(pRender->getNode());
CC_BREAK_IF(pAr == NULL);
TriggerMng::getInstance()->addArmatureMovementCallBack(pAr, this, movementEvent_selector(ArmatureActionState::animationEvent));
} while (0);
return true;
}