目标:实现下面2种效果:
1.
2.
直接上代码:
效果一:
txt = Label::create("this is a clippingNode Test...this is a clippingNode Test...","Arial",30); txt->setColor(Color3B::RED); //裁剪内容 ClippingNode* clip = ClippingNode::create(); Sprite* sp = Sprite::create("CloseNormal.png"); //裁剪模板 sp->setScaleX(5); sp->setAnchorPoint(Vec2::ZERO); clip->setStencil(sp); txt->setAnchorPoint(Vec2::ZERO); clip->addChild(txt); clip->setInverted(false); //设置裁剪区域可见还是非裁剪区域可见 这里为裁剪区域可见 clip->setAlphaThreshold(0); clip->setPosition(100,600); this->addChild(clip); MoveBy* to1 = MoveBy::create(5,Vec3(txt->getContentSize().width - 200,0)); //来回滚动动画 sp->runAction(RepeatForever::create(Sequence::create(to1,to1->reverse(),NULL)));
效果二:
Label* txt = Label::create("this is a clippingNode Test...this is a clippingNode Test...",30); txt->setColor(Color3B::RED); //裁剪内容 ClippingNode* clip = ClippingNode::create(); Sprite* sp = Sprite::create("CloseNormal.png"); //裁剪模板 sp->setScaleX(5); sp->setAnchorPoint(Vec2::ZERO); clip->setStencil(sp); txt->setAnchorPoint(Vec2::ZERO); clip->addChild(txt); clip->setInverted(false); //设置裁剪区域可见还是非裁剪区域可见 这里为裁剪区域可见 clip->setAlphaThreshold(0); clip->setPosition(100,600); this->addChild(clip); txt->setPositionX(clip->getContentSize().width); MoveTo* to2 = MoveTo::create(5,Vec3(-txt->getContentSize().width,0)); txt->runAction(Sequence::create(DelayTime::create(5),to2,NULL));原文链接:https://www.f2er.com/cocos2dx/340831.html