2016年6月3日 星期五

0603 如何合併圖跟DrawNODE


http://stackoverflow.com/questions/35322773/how-to-blend-two-drawnodes-in-cocos2d

 need some help with cocos2d DrawNodes blending. I have DrawNode with sprite on it:
enter image description here And another DrawNode with drawn polygon (polygon area is less than heart sprite). As a result of blending I need to have only a part of heart sprite inside polygon, like this: enter image description here My code: TextureNode.h

It seems that you want to clip the heart sprite using the polygon as a stencil. In that case. You don't have to blend two DrawNode. Instead, You can use ClippingNode like:
auto heartSprite = cocos2d::Sprite::create(fileName);

auto stencil = DrawNode::create();
stencil->drawPolygon(verts, count, cocos2d::Color4F::WHITE, 1, cocos2d::Color4F::WHITE);

auto clipper = ClippingNode::create();
clipper->setStencil(stencil);
clipper->addChild(heartSprite)
For more ClippingNode examples, you can refer to the official sample code:https://github.com/cocos2d/cocos2d-x/tree/v3/tests/cpp-tests/Classes/ClippingNodeTest

沒有留言:

張貼留言

cocos2dx-lua 建立滑鼠監聽

重要關鍵字  EVENT_MOUSE_SCROLL addEventListenerWithSceneGraphPriority      if IsPc() then --建立滑鼠監聽         local listener = cc.EventListenerMouse...