cocos2d-x 3.x 橡皮擦功能

时间:2024-01-13 11:10:08

1.HelloWorldScene.h

cocos2d::DrawNode* _eraser;
cocos2d::RenderTexture*_renderTexture;

2.HelloWorldScene.cpp 的init方法中

Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 center=Vec2(visibleSize.width*0.5f+origin.x,visibleSize.height*0.5f+origin.y);
_eraser=DrawNode::create();
_eraser->drawDot(Vec2::ZERO,,Color4F(,,,));
_eraser->retain(); _renderTexture=RenderTexture::create((int)visibleSize.width,(int)visibleSize.height);
_renderTexture->setPosition(center);
addChild(_renderTexture); Sprite*spirte=Sprite::create("title_bg.jpg");
spirte->setAnchorPoint(Vec2(0.5f,0.5f));
spirte->setPosition(center);
spirte->retain(); _renderTexture->begin();
spirte->visit();
_renderTexture->end();

3.触摸移动回调函数

Vec2 pos=touch->getLocation();//鼠标位置

_eraser->setPosition(pos);

BlendFunc blendFunc={GL_ONE,GL_ZERO};
_eraser->setBlendFunc(blendFunc); _renderTexture->begin();
_eraser->visit();
_renderTexture->end();