Blend Mode For Draw & Erase

I am developing a paint app. I want to make basic brush and erase. I tried blend mode drawNode.setBlendFunc(gl.ZERO,gl.ONE_MINUS_SRC_ALPHA); for eraser but it is not working. Are there anbody help me? İf there is anyway to develop eraser please tell me :relaxed:

check this out maybe it can Help:

http://zengrong.net/post/2067.htm

2 Likes
erase.setBlendFunc(  cc.ZERO, cc.ONE_MINUS_SRC_ALPHA );

works for me.

Thanks for everyone. Joseph’s example is perfect :blush:

Any idea how to do this in Cocos Creator?

Looks like RenderTexture isn’t part of cocos creator.

currently I have this code in creator’s canvas onLoad Function…

It draws the brush fine and follows the touch movement, now if I can just get it to interact with a sprite to erase it’s pixels…

        var brush = new cc.Node('brush01');
        var sprite = brush.addComponent(cc.Sprite);
        sprite.spriteFrame = this.brush;
        sprite.srcBlendFactor = cc.BlendFunc.BlendFactor.ZERO;
        sprite.dstBlendFactor = cc.BlendFunc.BlendFactor.ONE_MINUS_SRC_ALPHA;
        brush.parent = this.node.parent;
        brush.setPosition(0,0);
        brush.setScale(0.1 ,0.1 );
        brush.opacity = 255;
        
        
        this.node.on(cc.Node.EventType.TOUCH_START, function (event) {
            //eraseAtPoint(event.getLocation(), brush);
            //brush.setPosition(event.getLocation());
        });
        
        this.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
            eraseAtPoint(event.getLocation(), brush);
            //brush.setPosition(event.getLocation());
        });
        
        this.node.on(cc.Node.EventType.TOUCH_END, function (event) {
            brush.setPosition(-100,-100);
        })
        
        var eraseAtPoint = function(pt,brush){
            brush.setPosition(pt);
        }

@slackmoehrle any idea?

I may just have to drop Cocos Creator and use standard Cocos2d-x api.

Let me ask someone to look at your question.

1 Like

@slackmoehrle I’m guessing it’s not possible in cocos creator yet. Will just use Cocos2d-x CLI

I’m not sure and it is the weekend for the engineering team, so I’d assume they will answer this soon.

Alright I’ll look forward to hearing back from them. I’d like to use the latest iteration of cocos (‘cocos creator’) if possible.

Never heard back on this. I got it to work in cocos2d-x but not cocos creator… Any update on blend modes in cocos creator?

@slackmoehrleany update?

@nantas any thoughts?

Is there any way we can found the erase percentage? I mean how much texturein term of percenetage still remaining ?