kingBook

导航

cocos2d-x 3.x 橡皮擦功能

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,10,Color4F(0,0,0,0));
_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();

 

posted on 2016-06-08 16:56  kingBook  阅读(641)  评论(0编辑  收藏  举报