先看下效果
制造这个椭圆高亮区域所使用原图是
附上代码
bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); ………… ………… m_pTarget = CCRenderTexture::create(visibleSize.width, visibleSize.height, kCCTexture2DPixelFormat_RGBA8888); m_pTarget->setPosition(ccp(visibleSize.width / 2, visibleSize.height / 2)); addChild(m_pTarget, 10000); return true; } void HelloWorld::setHighlightRect(const cocos2d::CCRect& rect) { CCSprite* pMask = CCSprite::create("btn-about-normal.png"); pMask->setPosition(ccp(rect.origin.x,rect.origin.y)); pMask->setAnchorPoint(ccp(0,0)); pMask->setScaleX(rect.size.width/pMask->getContentSize().width); pMask->setScaleY(rect.size.height/pMask->getContentSize().height); ccBlendFunc blend; blend.src = GL_ZERO; blend.dst = GL_ONE_MINUS_SRC_ALPHA; pMask->setBlendFunc(blend); m_pTarget->clear(0,0,0,0.8f); m_pTarget->begin(); pMask->visit(); m_pTarget->end(); }