- boolHelloWorld::init()
- {
- if(!Layer::init())
- returnfalse;
- }
- SizevisibleSize=Director::getInstance()->getVisibleSize();
- autosprite=Sprite::create("HelloWorld.png");
- sprite->setPosition(Vec2(visibleSize.width/2,visibleSize.height/2));
- this->addChild(sprite);
- dotNode=DrawNode::create();
- dotNode->retain();
- dotNode->drawDot(Point(0,0),4.0f,Color4F(255,255));
- autopBg=Sprite::create("bg.png");//这个作为当“油漆层”
- pBg->setAnchorPoint(Point(0.5,0.5));
- pBg->setPosition(Vec2(visibleSize.width/2,visibleSize.height/2));
- pRender=RenderTexture::create(visibleSize.width,visibleSize.height);
- pRender->setPosition(Vec2(visibleSize.width/2,153);font-size:14px;border:none;background-color:inherit;">this->addChild(pRender);//渲染纹理层需加入该父节点层
- pRender->begin();
- pBg->visit();
- pRender->end();
- autolistener=EventListenerTouchOneByOne::create();
- listener->onTouchBegan=CC_CALLBACK_2(HelloWorld::onTouchBegan,this);
- listener->onTouchMoved=CC_CALLBACK_2(HelloWorld::onTouchMoved,153);font-size:14px;border:none;background-color:inherit;">this);
- listener->onTouchEnded=CC_CALLBACK_2(HelloWorld::onTouchEnded,0);background-color:inherit;">_eventDispatcher->addEventListenerWithSceneGraPHPriority(listener,153);font-size:14px;border:none;background-color:inherit;">true;
- }
voidHelloWorld::onTouchMoved(Touch*touch,Event*unused_event)
autotouchPoint=touch->getLocation();
dotNode->setPosition(touchPoint.x,touchPoint.y);
//设置混合模式
BlendFuncblendFunc={GL_ONE,GL_ZERO};
dotNode->setBlendFunc(blendFunc);
//将橡皮擦的像素渲染到画布上,与原来的像素进行混合
pRender->begin();
dotNode->visit();
pRender->end();
效果图:
原文链接:https://www.f2er.com/cocos2dx/338221.html