Exemplo n.º 1
0
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());
	}
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
 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);
     }
 }
Exemplo n.º 5
0
// 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));
			imgPromotion->addChild(card1,2,1001);
        }
    }
    if(_rootNode && _rootNode->getChildByName("lblProductName")){
        Text* lblProductName=dynamic_cast<Text*>(_rootNode->getChildByName("lblProductName"));// (CCLabelTTF*)this->getChildByTag(2001);
        lblProductName->setString(m_PrmtPrdct.m_strProductName);
    }


	auto btnContine = dynamic_cast<Button*>(_rootNode->getChildByName("btnContine"));
	btnContine->setTag(1001);
	btnContine->addTouchEventListener(CC_CALLBACK_2(GameWin::touchButton, this));	

	auto btnQuit = dynamic_cast<Button*>(_rootNode->getChildByName("btnQuit"));
	btnQuit->setTag(1002);
	btnQuit->addTouchEventListener(CC_CALLBACK_2(GameWin::touchButton, this));	

	auto btnBuyNow = dynamic_cast<Button*>(_rootNode->getChildByName("btnBuyNow"));
	btnBuyNow->setTag(1003);
	btnBuyNow->addTouchEventListener(CC_CALLBACK_2(GameWin::touchButton, this));	

	auto btnShare = dynamic_cast<Button*>(_rootNode->getChildByName("btnShare"));
	btnShare->setTag(1004);
	btnShare->addTouchEventListener(CC_CALLBACK_2(GameWin::touchButton, this));	


	//Show Total User Score
	long l_coins = app->GetUserTotalScore();
	char p[20];
	sprintf(p, "%ld", l_coins);
	string sTotal = p;
	
	iReward = app->getReward();
	iStar = app->getStar();
	char p1[20];
	sprintf(p1, "%ld", iReward);
	string sReward = p1;
	app->setReward(0,0);

	auto lblReward = dynamic_cast<::ui::Text*>(_rootNode->getChildByName("lblReward"));
	if (lblReward)
	{
		lblReward->setString(sReward);
	}
	auto lblScore = dynamic_cast<::ui::Text*>(_rootNode->getChildByName("lblScore"));
	if (lblReward)
	{
		lblScore->setString(sTotal);
	}


	//_rootNode->getChildByName("Img_Box")->setVisible(false);
	auto imgStar = dynamic_cast<ImageView*>(_rootNode->getChildByName(WIN_STAR_FRAME));	
	if (imgStar != nullptr) {
		_rootNode->getChildByName(WIN_STAR_BOX)->setVisible(false);
		if (iStar == 3){
			imgStar->loadTexture(WIN_STAR_3);
		}
		else if (iStar == 2){
			imgStar->loadTexture(WIN_STAR_2);
		}
		else if (iStar == 1){
			imgStar->loadTexture(WIN_STAR_1);
		}
	}
	if (app->getBGMstatus() == BGMusic_flag::ON)
	{
		app->PlayEffect(SOUND_WIN);
	}


		// start ansyc method load the atlas.png
	//Director::getInstance()->getTextureCache()->addImageAsync("MatchBg.png", CC_CALLBACK_1(GameWin::loadingCallBack, this));
	
	/*auto card1 = Sprite::create("match_game_img_1_b.jpg");
	// card1->setPosition(Vec2(visiableSize.width / 2 +88 * generalscalefactor,   visiableSize.height/2 +50 *generalscalefactor));
	 //float zoom_x = visiableSize.width *0.5 / card1->getContentSize().width;
	// float zoom_y = visiableSize.height * 0.5 / card1->getContentSize().height;
	 card1->setScale(150/800);
	 //card1->setScaleY(zoom_y);
	 
	 Image* image = new Image();
	 image->s
	 Texture2D* texture = new Texture2D();
    
	Sprite* sprite = dynamic_cast<Sprite*>(_rootNode->getChildByName("spPromotionImg"));  //spPromotionImg
	sprite->initWithFile("match_game_img_1_b.jpg");

	  this->addChild(card1,1,1001);
	*/


	Sprite* imgBackground = Sprite::create(WIN_BACKGROUND);

	imgBackground->setAnchorPoint(Vec2(0, 0));
	imgBackground->setPosition(Vec2(0, 0));
	this->addChild(imgBackground, -1, 222); 


	syncFlow();//sync with server
	app->PlayEffect(SOUND_GAME_PASS);

    return true;
}