您好,登錄后才能下訂單哦!
游戲中經(jīng)常會(huì)使用一些mask, 來(lái)做遮罩,實(shí)現(xiàn)不規(guī)則圖的顯示,在cocos2d-x中
函數(shù)實(shí)現(xiàn)如下:
.h
- static CCSprite* createMaskedSprite(CCSprite* src, const char* maskFile);
.cpp
- CCSprite* GOEUtilies::createMaskedSprite(CCSprite* src, const char* maskFile)
- {
- CCSprite * mask = CCSprite::create(maskFile);
- assert(src);
- assert(mask);
- CCSize srcContent = src->getContentSize();
- CCSize maskContent = mask->getContentSize();
- CCRenderTexture * rt = CCRenderTexture::create(srcContent.width, srcContent.height, kTexture2DPixelFormat_RGBA8888);
- float ratiow = srcContent.width / maskContent.width;
- float ratioh = srcContent.height / maskContent.height;
- mask->setScaleX(ratiow);
- mask->setScaleY(ratioh);
- mask->setPosition(ccp(srcContent.width / 2, srcContent.height / 2));
- src->setPosition(ccp(srcContent.width / 2, srcContent.height / 2));
- ccBlendFunc blendFunc2 = { GL_ONE, GL_ZERO };
- mask->setBlendFunc(blendFunc2);
- ccBlendFunc blendFunc3 = { GL_DST_ALPHA, GL_ZERO };
- src->setBlendFunc(blendFunc3);
- rt->begin();
- mask->visit();
- src->visit();
- rt->end();
- CCSprite * retval = CCSprite::createWithTexture(rt->getSprite()->getTexture());
- retval->setFlipY(true);
- return retval;
- }
使用方法為:
GOEUtilies::createMaskedSprite(sprite,"mask.png");
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。