Cocos2d-x   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了cocos2dx 实现跑马灯效果和文字效果大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

目标:实现下面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));

大佬总结

以上是大佬教程为你收集整理的cocos2dx 实现跑马灯效果和文字效果全部内容,希望文章能够帮你解决cocos2dx 实现跑马灯效果和文字效果所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。