直接把如下代码写到HelloWorld.cpp文件中即可:
// 创建裁剪节点
auto clipNode = ClippingNode::create();
auto spriteClip = CCSprite::create("game_title.png");
// 设置裁剪模板
clipNode->setStencil(spriteClip);
// 设置透明度阀值
clipNode->setAlphaThreshold(0);
// 设置裁剪节点大小
clipNode->setContentSize(CCSize(spriteClip->getContentSize().width, spriteClip->getContentSize().height));
// 获取裁剪节点大小
auto clipSize = clipNode->getContentSize();
clipNode->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2));
// 添加精灵到裁剪节点上
auto gameTitle = CCSprite::create("game_title.png");
auto spark = CCSprite::create("spark.png");
clipNode->addChild(gameTitle, 1);
spark->setPosition(Vec2(-visibleSize.width/2, 0));
clipNode->addChild(spark, 3);
this->addChild(clipNode, 5);
// 执行动作
auto moveAction = MoveTo::create(2.5f, Vec2(clipSize.width, 0));
auto delayTime = CCDelayTime::create(1.5f);
auto rePlace = CCPlace::create(Vec2(-clipSize.width, 0));
auto seq = Sequence::create(moveAction, delayTime, rePlace, NULL);
auto repeatAction = RepeatForever::create(seq);
spark->runAction(repeatAction);
效果如下图: (使用资源,一张标题图片,一张光效图 自己找两张就行了!!!)