RenderTexture setColor 无效

引擎版本 cocos2d-js-3.0-rc2 只有这个版本合并了颜色设置

cc.Sprite 扩展了一个setBorder(边框效果) 方法

/**
 * 给node 添加border
 * @param cr r
 * @param cg g
 * @param cb b
 * @param ca a
 * @param r 边框宽度
 * @param f 边框精细度 0 < f < r; default = 1
 * @returns {cc.RenderTexture}
 */
cc.Sprite.prototype.setBorder = function(cr, cg, cb, ca , r, f){
    var _dfc = cc.color.WHITE;
    r = r || (arguments.length == 2 ? cg : 5);
    f = f || 1;//精细度
    switch (arguments.length){
        case 0: cr = _dfc.r; cg = _dfc.g; cb = _dfc.b; ca = _dfc.a; break;
        case 1:
        case 2: cg = cr.g; cb = cr.b; ca = cr.a; cr = cr.r; break;
        case 3: ca = _dfc.a; break;
    }
    var that = this,
        x = that.x, y = that.y,
        w = that.width, h = that.height,
        dc = cc.size(w + r, h + r);
    that.removeBorder();

    var mTxt = new cc.RenderTexture(dc.width, dc.height),
        cx = 0,  ox = dc.width / 2, oy = dc.height / 2;

    var visitSprite = function(xx, yy){
        if(cc.sys.isNative){
            var spr = new cc.Sprite(that.getTexture());
            spr.attr({x : xx, y : yy, width :  w, height : h});
            spr.visit();
        } else {
            that.setPosition(xx, yy);
            that.visit();
        }
    };

    mTxt.beginWithClear(0, 0, 0, 0);
    for(var rd = 0; rd <= r; rd += f){
        cx = Math.sqrt(Math.pow(r, 2) - Math.pow(rd, 2));
        visitSprite(ox + rd, oy + cx);
        visitSprite(ox - rd, oy + cx);
        visitSprite(ox - rd, oy - cx);
        visitSprite(ox + rd, oy - cx);
    }
    mTxt.end();
    that.setPosition(x, y);

    var nTxt = new cc.RenderTexture(dc.width, dc.height);
    nTxt.setPosition(w / 2, h / 2);

    mTxt.setPosition(ox, oy);
    mTxt.getSprite().setBlendFunc(cc.ZERO, cc.SRC_ALPHA);
    nTxt.beginWithClear(cr, cg, cb, ca);
    mTxt.visit();
    nTxt.end();

    that.addChild(that.borderTex = nTxt, -1);
    return nTxt;
};

cc.Sprite.prototype.removeBorder = function(){
    this.borderTex && this.borderTex.removeFromParent(true);
};


```


使用代码
var testLayer = cc.Layer.extend({

    ctor : function(){
var spr = new cc.Sprite("xxxxxx.png");//图片随便
var sprBorder = spr.setBorder();//默认边框
spr.attr({x : cc.winSize.width / 2, y : cc.winSize.height / 2});
this.addChild(spr);

setTimeout(function(){
    //5秒钟后改变边框颜色
    sprBorder.setColor(cc.color.BLACK);//改变后无效果
    sprBorder.getSprite().setColor(cc.color.BLACK);//还是无效果
}, 5000);
}
});


```

效果如下. 白色边框是初始化的边框. 后改变颜色无效果
 

谢谢你的反馈,我们马上修复。

你好, 我测试了一下,没有问题呀。下面是我的测试代码:
var hair = new cc.Sprite(“style3.png”);
hair.setPosition(size.width / 2, size.height / 2);
this.addChild(hair, 10);

    //hair.setColor(cc.color.RED);

    window.hair = hair;

显示效果如下:

然后我设置边框:hair.setBorder()

再设置颜色:hair.setColor(cc.color.GREEN)

再设置成黑色:hair.setColor(cc.color.BLACK)

下面是我在console中设置的过程:

错了. 这样是正常的.

我说的是对RenderTexture setColor 无效
就是用RenderTexture 里面的 getSprite setColor 也是无效

谢谢提醒,该问题已解决,请更新一下这个PR:
https://github.com/cocos2d/cocos2d-html5/pull/2153

恩. 更新修改后已经可以了

你反馈的RenderTexture有些Action不能执行的问题已解决,请更新一下这个PR: https://github.com/cocos2d/cocos2d-html5/pull/2154

测试代码如下:
var hairSprite = new cc.Sprite(“style3.png”);
hairSprite.setPosition(size.width / 2, size.height / 2);
this.addChild(hairSprite, 10);
var hairBorder = hairSprite.setBorder(0,0,0,255,3);

    hairBorder.runAction(cc.sequence(cc.fadeOut(0.5, 0), cc.fadeIn(0.5,255)).repeatForever());

注意:
在使用RenderTexture(hairBorder)的getSprite时,如果你要将其加入到其他节点时,请先用removeFromParent将其从RenderTexture删除, 再用addChild来添加。

Thanks for feedback
David

已经可以了

Thanks David