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

使用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);

转载于:https://www.cnblogs.com/skyxu123/p/9543814.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值