参考学长的项目,记录一下刀光效果的实现。
bool KongJianLayer::init()
{
//调用父类的初始化
if ( !Layer::init() )
{
return false;
}
Vec2 origin=Director::getInstance()->getVisibleOrigin();
Size visibleSize=Director::getInstance()->getVisibleSize();
Sprite *title = Sprite::create("gameTitle2.png"); //初始化游戏标题
ClippingNode *cliper=ClippingNode::create(title);
Sprite* stencil = title; //设置剪裁模板为自
Sprite* spark = Sprite::create("titleBlend.png");//初始化亮片
spark->setPosition(-title->getContentSize().width,0); //设置亮片的位置
BlendFunc cbl = {GL_DST_COLOR, GL_ONE}; //定义混合类型
spark->setBlendFunc(cbl); //设置亮片混合
cliper->setAlphaThreshold(0.5f); //设置剪裁的透明度为0.5
cliper->setStencil(stencil); //设置剪裁模板
cliper->addChild(spark); //添加亮片
this->addChild(cliper,10); //添加剪裁到布景中
cliper->setPosition(Point(origin.x+visibleSize.width/2,origin.y+visibleSize.height-200));
MoveTo* moveTo = MoveTo::create(1.5f,Point(title->getContentSize().width,0));<span style="white-space:pre"> </span>//移动动画
Place* moveBack = Place::create(Point(-title->getContentSize().width,0)); <span style="white-space:pre"> </span>//瞬时回到某点
Sequence* seq = Sequence::create(moveTo,moveBack,DelayTime::create(1.0f),nullptr);<span style="white-space:pre"> </span>//顺序动作
RepeatForever* action = RepeatForever::create(seq); //重复执行的动作
spark->runAction(action); //亮片执行动作a
return true;
}bool KongJianLayer::i