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


C++ UILayer::getWidgetByName方法代码示例

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


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

示例1: 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;
}
开发者ID:NSJang,项目名称:CocoStudioSamples,代码行数:60,代码来源:HelloWorldScene.cpp

示例2: update

void HelloWorld::update(float delta)
{
	if(m_bStart)
	{
		CCArmature *pHero = (CCArmature*)(m_pGameScene->getChildByTag(10005)->getComponent("CCArmature")->getNode());
		pHero->getParent()->setPositionX(pHero->getParent()->getPositionX() + m_fSpeed);
		CCArmature *pEnemy = (CCArmature*)(m_pGameScene->getChildByTag(10006)->getComponent("CCArmature")->getNode());

		if(ccpDistance(ccp(pHero->getParent()->getPositionX(), 0), ccp(pEnemy->getParent()->getPositionX(), 0)) < m_fAttackDis)
		{	
			pHero->getAnimation()->play("attack");
			pHero->getAnimation()->setMovementEventCallFunc(this,
                                                        movementEvent_selector(HelloWorld::animationEvent));
			m_bStart = false;
		}
	}

	if(m_bDead)
	{
		CCComRender *pUIRender = static_cast<CCComRender*>(m_pGameScene->getChildByTag(10007)->getComponent("GUIComponent"));
		UILayer *pUILayer = static_cast<UILayer*>(pUIRender->getNode());
		UILoadingBar *pHPLoadingBar = static_cast<UILoadingBar*>(pUILayer->getWidgetByName("hp02_LoadingBar"));
		UILoadingBar *pMPLoadingBar = static_cast<UILoadingBar*>(pUILayer->getWidgetByName("mp02_LoadingBar"));

		pHPLoadingBar->setPercent(m_fPercentage);
		pMPLoadingBar->setPercent(m_fPercentage);

		m_fPercentage -= 2.0f;
        if (m_fPercentage < 0.0f) {
            unscheduleUpdate();
        }
	}
	
}
开发者ID:shujunqiao,项目名称:CocoStudioSamples,代码行数:34,代码来源:HelloWorldScene.cpp

示例3: onEnter

// on "init" you need to initialize your instance
void GameLoginLayer::onEnter()
{
    UILayer* uiLayer = UILayer::create();
    uiLayer->scheduleUpdate();
    
    UILayout* ui_root =dynamic_cast<UILayout*>(GUIReader::shareReader()->widgetFromJsonFile("plane_1.json"));
    uiLayer->addWidget(ui_root);
    
    UIButton *left_button = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("TextButton_34"));
    left_button->addReleaseEvent(this, SEL_ReleaseEvent(&GameLoginLayer::loginBtnCallback));
    
    m_CCLayer->addChild(uiLayer);
}
开发者ID:hetter,项目名称:planeX_Project,代码行数:14,代码来源:GameLoginLayer.cpp

示例4: init

bool GestureScene::init() {
    if ( !CCLayer::init() ) 
        return false;
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
	this->setTouchEnabled(true);

	UILayer* uiLayer = UILayer::create();  
    uiLayer->addWidget(GUIReader::shareReader()->widgetFromJsonFile("UI/GestureUI/GestureUI.json"));  

	UIPanel* rootPanel = (UIPanel*)uiLayer->getWidgetByName("rootPanel");
	xLabel = (UILabel*) rootPanel->getChildByName("touchXLabel");
	yLabel = (UILabel*) rootPanel->getChildByName("touchYLabel");
	resultLabel = (UILabel*) rootPanel->getChildByName("gestureNameLabel");

    this->addChild(uiLayer, 2);

    return true;
}
开发者ID:b99902062,项目名称:PaintHunter,代码行数:19,代码来源:GestureScene.cpp

示例5: 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(
                                        "visible.png",
                                        "visible.png",
                                        this,
                                        menu_selector(HelloWorld::btVisbleCallback));
    
	pCloseItem->setPosition(ccp(origin.x + visibleSize.width  - pCloseItem->getContentSize().width/2 ,
								origin.y + visibleSize.height - pCloseItem->getContentSize().height/2));

    // create menu, it's an autorelease object
    CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
    pMenu->setPosition(CCPointZero);
    this->addChild(pMenu, 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);
 


	/*Frame的测试*/
	
	Widget* frame = GUIReader::shareReader()->widgetFromJsonFile("UIRes/DemoLogin.ExportJson");
	
	UILayer* layer =UILayer::create();
	layer->setScale(0.8f); //缩放比例可以随便设置
	layer->addWidget(frame);
	this->addChild(layer);

	//触碰测试
	layer->getWidgetByName("login_Button")->addTouchEventListener(this,toucheventselector(HelloWorld::btMenuCallBack));
	layer->getWidgetByName("close_Button")->addTouchEventListener(this,toucheventselector(HelloWorld::btMenuCallBack));
	layer->getWidgetByName("agree_CheckBox")->addTouchEventListener(this,toucheventselector(HelloWorld::btMenuCallBack));
	layer->getWidgetByName("name_TextField")->addTouchEventListener(this,toucheventselector(HelloWorld::btMenuCallBack));
	layer->getWidgetByName("password_TextField")->addTouchEventListener(this,toucheventselector(HelloWorld::btMenuCallBack));
	layer->getWidgetByName("confirm_TextField")->addTouchEventListener(this,toucheventselector(HelloWorld::btMenuCallBack));

	//frame初始化,可以试一下不初始化,直接layer->setVisible(false);设置窗口不可见之后,鼠标点击原本的按钮区域,看看是否有对话框出现
	m_frame.setFrame(frame,(UIImageView*)layer->getWidgetByName("backageImg"));

	//设置触点在对话框外面时候的回调,在哪里设置对话框不可见,不可触碰
	m_frame.setTouchOutOfFrameEventListener(this,TouchOutOfFrameEvent_selector(HelloWorld::touchOutOfFrameCallback));

	m_frame.setFrameVisible(true);


    return true;
}
开发者ID:Arvin1991,项目名称:Cocos2dxUsefulClasses,代码行数:72,代码来源:HelloWorldScene.cpp

示例6: onEnter

void Scene_GameItem::onEnter()
{
    CCLayer::onEnter();
    this->initData();
    
    //隐藏pk界面
    this->setPkView(false);
	CCSprite* pSpriteBG = (CCSprite*)getChildByTag(eGameItemTagBg);
	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	//pSpriteBG->setPosition(ccp(visibleSize.width/2 , pSpriteBG->getContentSize().height/2 + origin.y));
	

	char str1[100]={0};
	switch(GameShare_Global::shareGlobal()->gameType)
	{
	case 1:
		sprintf(str1,"GameSceneBg1.json");
		break;
	case Game_Jelly:
		sprintf(str1,"GameSceneBg2.json");
		break;
	case Game_Fruit: 
		sprintf(str1,"GameSceneBg3.json");
		break;
	case Game_Link:
		sprintf(str1,"GameSceneBg4.json");
		break;
	case Game_TaiKo: 
		sprintf(str1,"GameSceneBg5.json");
		break;
	case Game_Cir:
		sprintf(str1,"GameSceneBg1.json");
		break;
	default:
		break;
	}

	UILayer* ul = UILayer::create();
	auto myLayout = dynamic_cast<Layout*>(GUIReader::shareReader()->widgetFromJsonFile(CStringUtil::convertToUIResPath(str1).c_str()));
	ul->addWidget(myLayout);
	this->addChild(ul, 0, 100);
	ul->setTouchEnabled(false);

	int nGameType = GameShare_Global::shareGlobal()->gameType;
	if (nGameType==1)
	{
		UIImageView* pHill = dynamic_cast<UIImageView*>(ul->getWidgetByName("san"));
		UIImageView* pHill2 = dynamic_cast<UIImageView*>(ul->getWidgetByName("san2"));
		//CCActionInterval*  actionTo = CCScaleTo::create(2.0f, 0.5f);
		CCActionInterval*  actionBy = CCScaleBy::create(1.0f, 1.0f, 1.1f);
		CCActionInterval*  actionBy2 = CCScaleBy::create(1.0f, 1.1f, 1.0f);
		CCFiniteTimeAction* seq = CCSequence::create(actionBy, actionBy->reverse(),NULL);
		CCActionInterval * repeatForever =CCRepeatForever::create((CCActionInterval* )seq);
		CCFiniteTimeAction* seq1 = CCSequence::create(actionBy2, actionBy2->reverse(),NULL);
		CCActionInterval * repeatForever2 =CCRepeatForever::create((CCActionInterval* )seq1);
		pHill->runAction(repeatForever);
		pHill2->runAction(repeatForever2);
	}
	else if (nGameType==2)
	{
		UIImageView*  pCloud = dynamic_cast<UIImageView*>(ul->getWidgetByName("yun2"));
		UIImageView*  pCloud2 = dynamic_cast<UIImageView*>(ul->getWidgetByName("yun3"));
		CCActionInterval*  actionBy = CCScaleBy::create(1.5f, 1.2f, 1.0f);
		CCActionInterval*  actionBy2 = CCScaleBy::create(1.5f, 1.2f, 1.0f);
		CCFiniteTimeAction* seq1 = CCSequence::create(actionBy, actionBy->reverse(),NULL);
		CCFiniteTimeAction* seq2 = CCSequence::create(actionBy2, actionBy2->reverse(),NULL);
		CCActionInterval * repeatForever1 =CCRepeatForever::create((CCActionInterval* )seq1);
		CCActionInterval * repeatForever2 =CCRepeatForever::create((CCActionInterval* )seq2);
		pCloud->runAction(repeatForever1);
		pCloud2->runAction(repeatForever2);
	}
	else if (nGameType==3)
	{
		UIImageView*  pSugar = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_15"));
		UIImageView*  pSugar1 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_20"));
		CCRotateBy* actionBy2 = CCRotateBy::create(1.5f, -25.0f, -25.0f);
		CCRotateBy* actionBy1 = CCRotateBy::create(1.5f, -25.0f, -25.0f);
		CCFiniteTimeAction* seq1 = CCSequence::create(actionBy2, actionBy2->reverse(), NULL);
		CCFiniteTimeAction* seq2 = CCSequence::create(actionBy1, actionBy1->reverse(), NULL);
		CCActionInterval * repeatForever1 =CCRepeatForever::create((CCActionInterval* )seq1);
		CCActionInterval * repeatForever2 =CCRepeatForever::create((CCActionInterval* )seq2);
		pSugar->runAction(repeatForever1);
		pSugar1->runAction(repeatForever2);

		//星星
		UIImageView*  pXx1 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_23"));
		UIImageView*  pXx2 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_32"));
		UIImageView*  pXx3 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_35"));
		UIImageView*  pXx4 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_39"));

		CCActionInterval*  actionBy3 = CCScaleBy::create(1.2f, 1.3f, 1.3f);
		CCActionInterval*  actionBy4 = CCScaleBy::create(1.2f, 1.3f, 1.3f);
		CCActionInterval*  actionBy5 = CCScaleBy::create(1.2f, 1.3f, 1.3f);
		CCActionInterval*  actionBy6 = CCScaleBy::create(1.2f, 1.3f, 1.3f);
		
		CCFiniteTimeAction* seq3 = CCSequence::create(actionBy3, actionBy3->reverse(),NULL);
		CCFiniteTimeAction* seq4 = CCSequence::create(actionBy4, actionBy4->reverse(),NULL);
		CCFiniteTimeAction* seq5 = CCSequence::create(actionBy5, actionBy5->reverse(),NULL);
		CCFiniteTimeAction* seq6 = CCSequence::create(actionBy6, actionBy6->reverse(),NULL);
		
//.........这里部分代码省略.........
开发者ID:anzhongliu,项目名称:SmallGame_Cocos2dx,代码行数:101,代码来源:Scene_GameItem.cpp

示例7: ccp

bool GameLayerPk2::init()
{
    if (!CCLayer::init()) {
        return false;
    }
    UILayer* ul = UILayer::create();
    auto myLayout = dynamic_cast<Layout*>(GUIReader::shareReader()->widgetFromJsonFile(CStringUtil::convertToUIResPath("Pk2.json").c_str()));
    ul->addWidget(myLayout);
    this->addChild(ul, 0, 100);
    
    UIButton* sureBtn = dynamic_cast<UIButton*>(ul->getWidgetByName("Sure"));
    sureBtn->setPressedActionEnabled(true);
    sureBtn->addReleaseEvent(this, coco_releaseselector(GameLayerPk2::sureBtnCallback));
    
    //设置自己的头像.
    UIImageView* cellBg = dynamic_cast<UIImageView*>(ul->getWidgetByName("Avatar1Bg"));
    CCSprite* img =  CCSprite::create();
    img->setContentSize(CCSize(145, 145));
    img->setAnchorPoint(ccp(0, 0));
    cellBg->addRenderer(img, 10);
    CImageDownloader::GetInstance()->SendHttpRequest(CPlayerInfoMan::sharedInstance().getPlayerInfo().strImg.c_str(), img, "1000", 1000);
    //设置自己的名字
    UILabel* nameLabel = dynamic_cast<UILabel*>(ul->getWidgetByName("Name1Label"));
    nameLabel->setText(CPlayerInfoMan::sharedInstance().getPlayerInfo().strName.c_str());
    
    //设置对方的头像
    UIImageView* cellBg2 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Avatar2Bg"));
    CCSprite* img2 =  CCSprite::create();
    img2->setContentSize(CCSize(145, 145));
    img2->setAnchorPoint(ccp(0, 0));
    cellBg2->addRenderer(img2, 10);
    CImageDownloader::GetInstance()->SendHttpRequest(CPkSysManager::sharedInstance().playerUrl.c_str(), img2, "1000", 1000);
    //设置对方名字
    UILabel* nameLabel2 = dynamic_cast<UILabel*>(ul->getWidgetByName("Name2Label"));
    nameLabel2->setText(CPkSysManager::sharedInstance().playerName.c_str());
    
    //设置自己的分数.
    CCSprite* score = NumSprite::getNumSprite(CPkSysManager::sharedInstance().myScore, "./CocoStudioResources/FriendListTimeNum", 17.0);
    score->setPosition(ccp(-35, 0));
    UIImageView* scoreBg1 = dynamic_cast<UIImageView*>(ul->getWidgetByName("ScoreBg"));
    scoreBg1->addRenderer(score, 10);

	//等待迎战;
	m_iSetTime = 1;
	Deng  = dynamic_cast<UIImageView*>(ul->getWidgetByName("Label1"));
	Dai   = dynamic_cast<UIImageView*>(ul->getWidgetByName("Label2"));
	Ying  = dynamic_cast<UIImageView*>(ul->getWidgetByName("Label3"));
	Zhan  = dynamic_cast<UIImageView*>(ul->getWidgetByName("Label4"));
	Dain1  = dynamic_cast<UIImageView*>(ul->getWidgetByName("Label5"));
	Dain2  = dynamic_cast<UIImageView*>(ul->getWidgetByName("Label6"));
	Dain3  = dynamic_cast<UIImageView*>(ul->getWidgetByName("Label7"));
	CCActionInterval*  actionTo = CCJumpTo::create(2, ccp(200,200),50, 4);  
	CCActionInterval*  actionBy = CCJumpBy::create(2, ccp(300,0), 50, 4);  
	actionUp = CCJumpBy::create(0.3f, ccp(0,0), 20,1); 
	CCActionInterval*  actionByBack = actionUp->reverse();

	//设置光效旋转
	UIImageView* Ray2 = dynamic_cast<UIImageView*>(ul->getWidgetByName("lightimg"));
	CCActionInterval * rotateto = CCRotateBy::create(6.0f, 360);
	CCFiniteTimeAction* seq1 = CCSequence::create(rotateto,NULL);
	CCActionInterval * repeatForever2 =CCRepeatForever::create((CCActionInterval* )seq1);
	Ray2->runAction(repeatForever2);
	//Deng->runAction( CCSequence::create(actionUp, NULL));  
	//Dai->runAction( CCSequence::create(actionUp, NULL));

// 	for(int i = 0;i<10;i++)
// 	{
// 		if(i%2==0)
// 		{
// 			
// 			Deng->runAction(actionByBack);
// 		}
// 		else{
// 			
// 			Dai->runAction(actionByBack);
// 		}
// 	}
	//this->schedule(schedule_selector(GameLayerPk2::SetDDTime), 0.2f);
	
	Deng->runAction( CCSequence::create((CCActionInterval*)actionUp->copy(),NULL));
	Dai->runAction( CCSequence::create((CCActionInterval*)actionUp->copy(),NULL));
	Ying->runAction( CCSequence::create((CCActionInterval*)actionUp->copy(),NULL)); 
	Zhan->runAction( CCSequence::create((CCActionInterval*)actionUp->copy(),NULL)); 
	Dain1->runAction( CCSequence::create((CCActionInterval*)actionUp->copy(),NULL)); 
	Dain2->runAction( CCSequence::create((CCActionInterval*)actionUp->copy(),NULL)); 
	Dain3->runAction( CCSequence::create((CCActionInterval*)actionUp->copy(),NULL));
    return true;
}
开发者ID:anzhongliu,项目名称:SmallGame_Cocos2dx,代码行数:88,代码来源:GameLayerPk2.cpp


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