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


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

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


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

示例1: selectTouchEvent

void SelectHeroLayer::selectTouchEvent(Ref* pSender, Widget::TouchEventType type)
{
	if( type == Widget::TouchEventType::ENDED)
	{
		Layout* selectItem = static_cast<Layout*>(pSender);

		//删除上次的粒子效果
		for(Widget* item : lstHero->getItems() )
		{
			ImageView* imgHero = static_cast<ImageView*>(Helper::seekWidgetByName(item, "imgHero"));
			imgHero->removeAllChildren();
		}

		ImageView* imgHero = static_cast<ImageView*>(Helper::seekWidgetByName(selectItem, "imgHero"));

		ParticleSystemQuad* particle = ParticleSystemQuad::create("particle_texture.plist");
		particle->setAutoRemoveOnFinish(true);
		imgHero->addChild(particle);
		particle->setPosition( Vec2(50 , 50)  );


		_selectedHero = static_cast<HeroModel*>(selectItem->getUserObject());
	}
}
开发者ID:baidang201,项目名称:MaiziGame,代码行数:24,代码来源:SelectHeroLayer.cpp

示例2: init

bool UIImageViewTest_ContentSize::init()
{
    if (UIScene::init())
    {
        Size widgetSize = _widget->getContentSize();
        
        Text* alert = Text::create("ImageView ContentSize Change", "fonts/Marker Felt.ttf", 26);
        alert->setColor(Color3B(159, 168, 176));
        alert->setPosition(Vec2(widgetSize.width / 2.0f,
                                widgetSize.height / 2.0f - alert->getContentSize().height * 2.125f));
        
        _uiLayer->addChild(alert);
        
        Text *status = Text::create("child ImageView position percent", "fonts/Marker Felt.ttf", 16);
        status->setColor(Color3B::RED);
        status->setPosition(Vec2(widgetSize.width/2, widgetSize.height/2 + 80));
        _uiLayer->addChild(status,20);
        
        // Create the imageview
        ImageView* imageView = ImageView::create("cocosui/buttonHighlighted.png");
        imageView->setScale9Enabled(true);
        imageView->setContentSize(Size(200, 80));
        imageView->setPosition(Vec2(widgetSize.width / 2.0f,
                                    widgetSize.height / 2.0f ));
       
        
        ImageView* imageViewChild = ImageView::create("cocosui/buttonHighlighted.png");
        imageViewChild->setScale9Enabled(true);
        imageViewChild->setSizeType(Widget::SizeType::PERCENT);
        imageViewChild->setPositionType(Widget::PositionType::PERCENT);
        imageViewChild->setSizePercent(Vec2::ANCHOR_MIDDLE);
        imageViewChild->setPositionPercent(Vec2::ANCHOR_MIDDLE);
        imageViewChild->setPosition(Vec2(widgetSize.width / 2.0f,
                                    widgetSize.height / 2.0f));
        
        ImageView* imageViewChild2 = ImageView::create("cocosui/buttonHighlighted.png");
        imageViewChild2->setScale9Enabled(true);
        imageViewChild2->setSizeType(Widget::SizeType::PERCENT);
        imageViewChild2->setPositionType(Widget::PositionType::PERCENT);
        imageViewChild2->setSizePercent(Vec2::ANCHOR_MIDDLE);
        imageViewChild2->setPositionPercent(Vec2::ANCHOR_MIDDLE);
        imageViewChild->addChild(imageViewChild2);
        
        
        imageView->addChild(imageViewChild);
        
        imageView->setTouchEnabled(true);
        imageView->addTouchEventListener([=](Ref* sender, Widget::TouchEventType type){
            if (type == Widget::TouchEventType::ENDED) {
                float width = CCRANDOM_0_1() * 200 + 50;
                float height = CCRANDOM_0_1() * 80 + 30;
                imageView->setContentSize(Size(width, height));
                
                imageViewChild->setPositionPercent(Vec2(CCRANDOM_0_1(), CCRANDOM_0_1()));
                status->setString(StringUtils::format("child ImageView position percent: %f, %f",
                                                      imageViewChild->getPositionPercent().x, imageViewChild->getPositionPercent().y));
            }
        });
        
        _uiLayer->addChild(imageView);
        
        return true;
    }
    return false;
}
开发者ID:AomXD,项目名称:workspace,代码行数:65,代码来源:UIImageViewTest.cpp

示例3: init

bool pauseUI::init()
{
    auto s = Director::getInstance()->getWinSize();
    auto layer = LayerColor::create(Color4B(100,100,100,90));
    addChild(layer);
    
    // Create the imageview
    ImageView* back = ImageView::create();
    back->setScale9Enabled(true);
    back->loadTexture("UI/green_edit.png");
    back->setSize(Size(s.width*0.8, s.height*0.4));
    back->setPosition(Point(s.width/2,s.height/2));
    this->addChild(back);
    
    
    const char* normal = "UI/normal.png";
    const char* pressed = "UI/press.png";
    
    // Add the alert
    gui::Text* alert = gui::Text::create();
    alert->setText("继续游戏");
    alert->setFontName("Marker Felt");
    alert->setFontSize(30);

    // Create the button //继续游戏
    Button* button = Button::create();
    button->setTouchEnabled(true);
    // open scale9 render
    button->setScale9Enabled(true);
    button->loadTextures(normal, pressed, "");
    button->setSize(Size(button->getContentSize().width*3, button->getContentSize().height));
    button->addChild(alert);
    button->addTouchEventListener(this, toucheventselector(pauseUI::continueButtonEvent));
    back->addChild(button);
    button->setPosition(Point(0, back->getSize().height/2 - button->getSize().height));

    
    Point lastPt = button->getPosition();
    
    int step = (back->getSize().height - button->getSize().height*3)/4;
    
    
    // Add the alert
    alert = gui::Text::create();
    alert->setText("重新开始");
    alert->setFontName("Marker Felt");
    alert->setFontSize(30);
    
    // Create the button //继续游戏
    button = Button::create();
    button->setTouchEnabled(true);
    // open scale9 render
    button->setScale9Enabled(true);
    button->loadTextures(normal, pressed, "");
    button->setSize(Size(button->getContentSize().width*3, button->getContentSize().height));
    button->setPosition(Point(0, lastPt.y - button->getContentSize().height-step));
    button->addChild(alert);
    button->addTouchEventListener(this, toucheventselector(pauseUI::restartButtonEvent));
    back->addChild(button);
    
    
    lastPt = button->getPosition();
    
    // Add the alert
    alert = gui::Text::create();
    alert->setText("回主界面");
    alert->setFontName("Marker Felt");
    alert->setFontSize(30);
    
    // Create the button //继续游戏
    button = Button::create();
    button->setTouchEnabled(true);
    // open scale9 render
    button->setScale9Enabled(true);
    button->loadTextures(normal, pressed, "");
    button->setSize(Size(button->getContentSize().width*3, button->getContentSize().height));
    button->setPosition(Point(0, lastPt.y - button->getContentSize().height-step));
    button->addChild(alert);
    button->addTouchEventListener(this, toucheventselector(pauseUI::backMainUIButtonEvent));
    back->addChild(button);
    
    auto scale = ScaleTo::create(1.0f, 1.0f);
    back->setScale(0.0f);
    back->runAction(EaseElasticOut::create(scale, 1.0f));
    return true;
}
开发者ID:rickystone,项目名称:Match2,代码行数:86,代码来源:pauseUI.cpp

示例4: setPropsWithFlatBuffers

 void ImageViewReader::setPropsWithFlatBuffers(cocos2d::Node *node, const flatbuffers::Table *imageViewOptions)
 {
     ImageView* imageView = static_cast<ImageView*>(node);
     auto options = (ImageViewOptions*)imageViewOptions;
     
     
     bool fileExist = false;
     std::string errorFilePath = "";
     auto imageFileNameDic = options->fileNameData();
     int imageFileNameType = imageFileNameDic->resourceType();
     std::string imageFileName = imageFileNameDic->path()->c_str();
     switch (imageFileNameType)
     {
         case 0:
         {
             if (FileUtils::getInstance()->isFileExist(imageFileName))
             {
                 fileExist = true;
             }
             else
             {
                 errorFilePath = imageFileName;
                 fileExist = false;
             }
             break;
         }
             
         case 1:
         {
             std::string plist = imageFileNameDic->plistFile()->c_str();
             SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(imageFileName);
             if (spriteFrame)
             {
                 fileExist = true;
             }
             else
             {
                 if (FileUtils::getInstance()->isFileExist(plist))
                 {
                     ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist);
                     ValueMap metadata = value["metadata"].asValueMap();
                     std::string textureFileName = metadata["textureFileName"].asString();
                     if (!FileUtils::getInstance()->isFileExist(textureFileName))
                     {
                         errorFilePath = textureFileName;
                     }
                 }
                 else
                 {
                     errorFilePath = plist;
                 }
                 fileExist = false;
             }
             break;
         }
             
         default:
             break;
     }
     if (fileExist)
     {
         imageView->loadTexture(imageFileName, (Widget::TextureResType)imageFileNameType);
     }
     else
     {
         auto label = Label::create();
         label->setString(__String::createWithFormat("%s missed", errorFilePath.c_str())->getCString());
         imageView->addChild(label);
     }
     
     bool scale9Enabled = options->scale9Enabled();
     imageView->setScale9Enabled(scale9Enabled);
     
     auto widgetReader = WidgetReader::getInstance();
     widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions());
     
     if (scale9Enabled)
     {
         imageView->setUnifySizeEnabled(false);
         imageView->ignoreContentAdaptWithSize(false);
         
         auto f_scale9Size = options->scale9Size();
         Size scale9Size(f_scale9Size->width(), f_scale9Size->height());
         imageView->setContentSize(scale9Size);
         
         
         auto f_capInset = options->capInsets();
         Rect capInsets(f_capInset->x(), f_capInset->y(), f_capInset->width(), f_capInset->height());
         imageView->setCapInsets(capInsets);
     }
     else
     {
         Size contentSize(options->widgetOptions()->size()->width(), options->widgetOptions()->size()->height());
         imageView->setContentSize(contentSize);
     }
 }
开发者ID:Ratel13,项目名称:cocos-reader,代码行数:96,代码来源:ImageViewReader.cpp

示例5: init

// on "init" you need to initialize your instance
bool GameWin::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
   
    Size visiableSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
	

	AppDelegate *app = (AppDelegate*)Application::getInstance();
	  std::string sCSD=app->GetLayoutString();
	 _rootNode = CSLoader::createNode("res/game_passed/GamePassLayer"+sCSD+".csb");

	 //loginLayer=Layer::create();
	 addChild(_rootNode,1);

	 /*
	LayerColor *layer1 = LayerColor::create(Color4B(0, 0, 0, 180));
	TurntableSystem* price =new TurntableSystem(layer1);
	layer1->setTag(CHILD_TURNTABLE);
	addChild(layer1,99);*/
	

	/*
	cocostudio::ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("Animation0.png", "Animation0.plist", "Animation.ExportJson");
	cocostudio::Armature *armature = cocostudio::Armature::create("Animation");
	armature->getAnimation()->playByIndex(0);
	armature->setScale(0.5f);
	armature->setPosition(ccp(visibleSize.width * 0.5, visibleSize.height * 0.5));
	this->addChild(armature);
	
	*/

	 /*
	cocostudio::Armature* armature;
	cocostudio::ArmatureDataManager::getInstance()->addArmatureFileInfo("res/animations/coin/coin.ExportJson");
	armature = cocostudio::Armature::create("coin");
	if (armature){
		armature->setPosition(ccp(visiableSize.width * 0.8, visiableSize.height * 0.5));
		armature->getAnimation()->playByIndex(0);
		armature->setScale(0.25);
		this->addChild(armature);
	}
	*/
	


	//Get Promotion 
	// Setting HTTP Request Header
 //   if(m_iIsLoad==0){
 //       m_iIsLoad=1;
	//HttpRequest* request = new HttpRequest();
 //   request->setUrl(PromotionWebGetURL);
 //   request->setRequestType(HttpRequest::Type::GET);
 //   request->setResponseCallback(CC_CALLBACK_2(GameWin::onHttpRequestCompleted,this));
 //   request->setTag("GET test");
 //   cocos2d::network::HttpClient::getInstance()->send(request);
 //   request->release();
 //   }

	//ImageView* imgPromotion = dynamic_cast<ImageView*>(_rootNode->getChildByName("ivPromotionImg")); 
	//	 auto card1 = Sprite::create("match_game_img_1_b.jpg");
	// //card1->setPosition(Vec2(0, imgPromotion->getPositionY()+ imgPromotion->getContentSize().height/2));
	//	log("1=%f,%f,%f,%f",imgPromotion->getPositionX(),imgPromotion->getPositionY(),imgPromotion->getContentSize().width,imgPromotion->getContentSize().height);
	//	card1->setAnchorPoint(Vec2(0,0)); 
	//card1->setPosition(Vec2(0, 0));
	// //float zoom_x = visiableSize.width *0.5 / card1->getContentSize().width;
	//// float zoom_y = visiableSize.height * 0.5 / card1->getContentSize().height;
	// //card1->setScale(0.055f);
	// //card1->setScaleY(zoom_y);
	//card1->setScale(0.38f);
	//  imgPromotion->addChild(card1,2,1001);

	m_PrmtPrdct = app->getPromoteProduct();

	if(m_PrmtPrdct.m_iIsLoad == 0){
        
		m_PrmtPrdct.m_iIsLoad=1;
		HttpRequest* request = new HttpRequest();
		request->setUrl(PromotionWebGetURL);
		request->setRequestType(HttpRequest::Type::GET);
		request->setResponseCallback(CC_CALLBACK_2(GameWin::onHttpRequestCompleted,this));
		request->setTag("GET test");
		cocos2d::network::HttpClient::getInstance()->send(request);
		request->release();
    }

	if(_rootNode){
        auto img=_rootNode->getChildByName("ivPromotionImg");
        if(img){
            ImageView* imgPromotion = dynamic_cast<ImageView*>(_rootNode->getChildByName("ivPromotionImg"));
			auto card1 = Sprite::create(m_PrmtPrdct.m_strImage.c_str());
			card1->setAnchorPoint(Vec2(0,0)); 
			card1->setPosition(Vec2(0, 0));
			card1->setScale((imgPromotion->getBoundingBox().size.width / card1->getContentSize().width));
//.........这里部分代码省略.........
开发者ID:zhuanglm,项目名称:TweeBaaMobileApp,代码行数:101,代码来源:GameWinScene.cpp


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