Blend Mode For Draw & Erase

Blend Mode For Draw & Erase
0.0 0

#1

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:


#2

check this out maybe it can Help:

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


#3
erase.setBlendFunc(  cc.ZERO, cc.ONE_MINUS_SRC_ALPHA );

works for me.


#4

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


#5

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);
        }

#6

@slackmoehrle any idea?

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


#7

Let me ask someone to look at your question.


#8

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


#9

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


#10

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


#11

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?


#12

@slackmoehrleany update?


#13

@nantas any thoughts?


#14

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