12
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

cocos2d-xAdvent Calendar 2013

Day 21

画像でマスクする

Last updated at Posted at 2013-12-21

Cocos2d-xのCCClipingNodeクラスを使ってマスクする方法を共有します。
以下の例では、画面と同じ大きさの真っ白なノードを用意して、それを画像でマスクしています。

CCSize winSize = CCDirector::sharedDirector()->getWinSize();

// マスクされる白いノード
CCDrawNode *content = CCDrawNode::create();
CCPoint vectors[] = { ccp(-winSize.width / 2, winSize.height / 2),
                      ccp(winSize.width / 2, winSize.height / 2),
                      ccp(winSize.width / 2, winSize.height / 2),
                      ccp(winSize.width / 2, winSize.height / 2) };
ccColor4F white = ccc4FFromccc3B(ccWHITE);
// vectors, count, fillColor, borderWidth, borderColor
content->drawPolygon(vectors, 4, white, 0, white);

// マスクするノード
CCSprite *mask = CCSprite::create("mask.png");

// 白いノードをマスクする
CCClippingNode *clippingNode = CCClippingNode::create();
// マスクするノードを設定
clippingNode->setStencil(mask);
// マスクの閾値の設定
clippingNode->setAlphaThreshold(0.01f);
// マスクされるノードを設定(白いノード)
clippingNode->addChild(content);

// マスクしたノードを表示する
clippingNode->setPosition(winSize.width / 2, winSize.height / 2);
this->addChild(clippingNode);

mask.png :
HelloWorld.png

結果 :
ss_12-21-2013_18-21-50.png

12
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?