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

cocos2d-x颜色混合模式完成光照效果

发布时间:2020-12-14 21:06:15 所属栏目:百科 来源:网络整理
导读:使用Cocosd-x3.2的颜色混合功能和裁剪功能完成光照效果,简单易用,效果图如下: 代码: //底图,光照图(一般是有透明度的白色图) 光移动的时间,循环次数 Node * HelloWorld ::createFlashNode (const std ::string spName,const std ::string splashName

使用Cocosd-x3.2的颜色混合功能和裁剪功能完成光照效果,简单易用,效果图如下:

代码:

//底图,光照图(一般是有透明度的白色图) 光移动的时间,循环次数
Node * HelloWorld::createFlashNode(const std::string &spName,const std::string &splashName,float duration,int loops)
{
    auto clNode = ClippingNode::create();
    auto stecil = Sprite::create(spName);
    clNode -> setStencil(stecil);
    clNode -> setAlphaThreshold(0.1);

    auto star = Sprite::create(spName);
    clNode -> addChild(star);

    auto splash = Sprite::create(splashName);
    star -> addChild(splash);
     //关键代码
    splash -> setBlendFunc({GL_DST_COLOR,GL_ONE});
// splash -> setPosition(splash->getContentSize().width/2-star->getContentSize().width,splash->getContentSize().height/2);

    auto place = Place::create(Vec2(splash->getContentSize().width/2-star->getContentSize().width,splash->getContentSize().height/2));
    auto moto = MoveTo::create(duration,Vec2(splash->getContentSize().width/2+star->getContentSize().width,splash->getContentSize().height/2));
    auto seq = Sequence::create(place,moto,NULL);
    ActionInterval *repeat = nullptr;
    if (loops!=-1)
    {
        repeat = Repeat::create(seq,loops);
    }
    else
    {
        repeat = RepeatForever::create(seq);
    }
    splash -> runAction(repeat);

    return clNode;
}

//调用
auto no = createFlashNode("xingxing.png","light.png",2);
this -> addChild(no);
 no -> setPosition(300,300);

(编辑:李大同)

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

    推荐文章
      热点阅读