cocos2d实现刮奖效果

前端之家收集整理的这篇文章主要介绍了cocos2d实现刮奖效果前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. boolHelloWorld::init()
  2. {
  3. if(!Layer::init())
  4. returnfalse;
  5. }
  6. SizevisibleSize=Director::getInstance()->getVisibleSize();
  7. autosprite=Sprite::create("HelloWorld.png");
  8. sprite->setPosition(Vec2(visibleSize.width/2,visibleSize.height/2));
  9. this->addChild(sprite);
  10. dotNode=DrawNode::create();
  11. dotNode->retain();
  12. dotNode->drawDot(Point(0,0),4.0f,Color4F(255,255));
  13. autopBg=Sprite::create("bg.png");//这个作为当“油漆层”
  14. pBg->setAnchorPoint(Point(0.5,0.5));
  15. pBg->setPosition(Vec2(visibleSize.width/2,visibleSize.height/2));
  16. pRender=RenderTexture::create(visibleSize.width,visibleSize.height);
  17. pRender->setPosition(Vec2(visibleSize.width/2,153);font-size:14px;border:none;background-color:inherit;">this->addChild(pRender);//渲染纹理层需加入该父节点层
  18. pRender->begin();
  19. pBg->visit();
  20. pRender->end();
  21. autolistener=EventListenerTouchOneByOne::create();
  22. listener->onTouchBegan=CC_CALLBACK_2(HelloWorld::onTouchBegan,this);
  23. listener->onTouchMoved=CC_CALLBACK_2(HelloWorld::onTouchMoved,153);font-size:14px;border:none;background-color:inherit;">this);
  24. listener->onTouchEnded=CC_CALLBACK_2(HelloWorld::onTouchEnded,0);background-color:inherit;">_eventDispatcher->addEventListenerWithSceneGraPHPriority(listener,153);font-size:14px;border:none;background-color:inherit;">true;
  25. }

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

    猜你在找的Cocos2d-x相关文章