Example #1
0
void GameResultSuccess::playWingAction(void)
{
	auto NodeWing = (Node*)GameMainLayer::seekNodeByName(_myLayer, "NodeWing");
	NodeWing->setScale(1.2f);
	// 右流光效果
	auto imgLeftWing = Sprite::create("ccsRes/resResoutLayer/ImgWing.png");
	imgLeftWing->setAnchorPoint(Vec2(0, 0.5));

	Size clipSize = imgLeftWing->getContentSize();
	Sprite* spark = Sprite::create("FirstUIRes/Sptigeguang.png");
	spark->setScaleY(1.2f);
	//spark->setPosition(-clipSize.width, -50);

	ClippingNode* clippingLeftNode = ClippingNode::create();
	NodeWing->addChild(clippingLeftNode);

	clippingLeftNode->setAlphaThreshold(0.05f); //设置alpha闸值  
	clippingLeftNode->setContentSize(clipSize); //设置尺寸大小  

	clippingLeftNode->setStencil(imgLeftWing);   //设置模板stencil  
	clippingLeftNode->addChild(imgLeftWing, 1);  //先添加标题,会完全显示出来,因为跟模板一样大小  
	clippingLeftNode->addChild(spark, 2);       //会被裁减  

	MoveTo* moveAction = MoveTo::create(1.0f, Vec2(clipSize.width, 0));
	MoveTo* moveBackAction = MoveTo::create(0.01f, Vec2(-clipSize.width, 0));
	spark->runAction(RepeatForever::create(Sequence::create(CCDelayTime::create(1.5f), moveAction, moveBackAction, NULL)));

	// 左流光效果
	auto imgRightWing = Sprite::create("ccsRes/resResoutLayer/ImgWing.png");
	imgRightWing->setFlipX(true);
	imgRightWing->setAnchorPoint(Vec2(1, 0.5));

	clipSize = imgRightWing->getContentSize();
	Sprite* rightspark = Sprite::create("FirstUIRes/Sptigeguang.png");
	rightspark->setFlipX(true);
	rightspark->setScaleY(1.2f);
	//spark->setPosition(-clipSize.width, -50);

	ClippingNode* clippingRightNode = ClippingNode::create();
	NodeWing->addChild(clippingRightNode);

	clippingRightNode->setAlphaThreshold(0.05f); //设置alpha闸值  
	clippingRightNode->setContentSize(clipSize); //设置尺寸大小  

	clippingRightNode->setStencil(imgRightWing);   //设置模板stencil  
	clippingRightNode->addChild(imgRightWing, 1);  //先添加标题,会完全显示出来,因为跟模板一样大小  
	clippingRightNode->addChild(rightspark, 2);       //会被裁减  

	MoveTo* moveAction1 = MoveTo::create(1.0f, Vec2(-clipSize.width, 0));
	MoveTo* moveBackAction1 = MoveTo::create(0.01f, Vec2(clipSize.width, 0));
	rightspark->runAction(RepeatForever::create(Sequence::create(CCDelayTime::create(1.5f), moveAction1, moveBackAction1, NULL)));
}
bool HelloWorld::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    
    visibleSize = Director::getInstance()->getVisibleSize();
	winSize = Director::getInstance()->getWinSize();
    origin = Director::getInstance()->getVisibleOrigin();


	Sprite* bg = Sprite::create("HelloWorld.png");
	bg->setPosition(visibleSize / 2);
	//this->addChild(bg, -1);


	Sprite* gameTitle = Sprite::create("game_title.png");

	Size clipSize = gameTitle->getContentSize();

	Sprite* spark = Sprite::create("spark.png");
	spark->setPosition(-clipSize.width, 0);


	ClippingNode* clippingNode = ClippingNode::create();
	clippingNode->setAlphaThreshold(0);
	clippingNode->setContentSize(clipSize);
	clippingNode->setPosition(visibleSize / 2);
	this->addChild(clippingNode);


	clippingNode->setStencil(gameTitle);   //设置模板

	clippingNode->addChild(gameTitle, 1);  //先添加标题,会完全显示出来,因为跟模板一样大小
	clippingNode->addChild(spark,2);       //会被裁减
	

	MoveTo* moveAction = MoveTo::create(2.0f, Vec2(clipSize.width, 0));
	MoveTo* moveBackAction = MoveTo::create(2.0f, Vec2(-clipSize.width, 0));
	Sequence* seq = Sequence::create(moveAction, moveBackAction, NULL);
	RepeatForever* repeatAction = RepeatForever::create(seq);
	spark->runAction(repeatAction); //进行左右移动的重复动作

    return true;
}