加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 16:43:16 所属栏目:百科 来源:网络整理
导读:目标:实现下面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*

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读