cocos2dx 实现跑马灯效果和文字效果

前端之家收集整理的这篇文章主要介绍了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));
原文链接:https://www.f2er.com/cocos2dx/340831.html

猜你在找的Cocos2d-x相关文章