CCTexture2D* Util::getGrayTexture(const char* filename){ typedef enum { RED = 0, GREEN = 1, BLUE = 2, ALPHA = 3 } PIXELS; CCImage *image = new CCImage(); image->initWithImageFile(filename); unsigned char* pixels = image->getData(); int len = image->getDataLen(); uint32_t *p = (uint32_t *)pixels; for(int i=0;i<len;i++){ uint8_t *rgbaPixel = (uint8_t *) &p[i]; //uint32_t gray = 0.3 * rgbaPixel[RED] + 0.59 * rgbaPixel[GREEN] + 0.11 * rgbaPixel[BLUE]; uint32_t gray = 1.2*rgbaPixel[RED] + 1.0*rgbaPixel[GREEN] + 0.0*rgbaPixel[BLUE]; // set the pixels to gray rgbaPixel[RED] = gray; rgbaPixel[GREEN] = gray; rgbaPixel[BLUE] = gray; } CCTexture2D* texture = new CCTexture2D(); texture->autorelease(); texture->initWithImage(image); image->release(); return texture; }
void CMainCityUI::imageLoadSuccessCallBack(string sTag, vector<char>* pBuffer) { CCImage* img = new CCImage; img->initWithImageData((unsigned char*)pBuffer->data(), pBuffer->size()); CCTexture2D* texture = new CCTexture2D(); texture->initWithImage(img); CLayout* headPart = (CLayout*)m_ui->findWidgetById("head_part"); CCSprite* head = (CCSprite*)headPart->getChildByTag(15); // head->removeFromParent(); //head->setTexture(texture); string path = HttpLoadImage::getInstance()->getStoragePath("download/fbImg",sTag.c_str())+".jpg"; string buff(pBuffer->begin(), pBuffer->end()); CCLOG("path: %s", path.c_str()); FILE *fp = fopen(path.c_str(), "wb+"); fwrite(buff.c_str(), 1, pBuffer->size(), fp); fclose(fp); // CCSprite *headbg = (CCSprite*)(m_ui->findWidgetById("headbg")); // CCClippingNode *clip = CCClippingNode::create(); // CCSprite *fbimg = CCSprite::createWithTexture(texture); // clip->addChild(fbimg); // // clip->setPosition(headbg->getPosition()); // clip->setContentSize(CCSizeMake(110,110)); // // static ccColor4F red ={1,0,1}; // float radius = 106; // const int nCount = 200; // const float angle = 2.0f* (float)M_PI/nCount; // CCPoint circle[nCount]; // for(int i=0; i<nCount; i++) // { // float radian = i*angle; // circle[i].x = radius * cosf(radian); // circle[i].y = radius * sinf(radian); // } // CCDrawNode *stencil= CCDrawNode::create(); // stencil->drawPolygon(circle,nCount,red,0,red); // clip->setStencil(stencil); // m_ui->addChild(clip); CCSprite *headBg = (CCSprite *)(headPart->findWidgetById("headbg")); CCSprite *headSpr = MakeFaceBookHeadToCircle(CCSprite::createWithTexture(texture)); headSpr->setTag(15); headSpr->setPosition(headBg->getPosition()); headPart->addChild(headSpr); head->removeFromParent(); img->release(); }
void AwaiterInfoNode::OnProfileImageResponse(CCHttpClient* client, CCHttpResponse* response) { if(response->getResponseCode() == 200) { std::vector<char> *buffer = response->getResponseData(); bool imgInit; CCImage * img = new CCImage(); if (img->initWithImageData(&(*buffer)[0], buffer->size(), CCImage::kFmtUnKnown)) { imgInit = true; CCLOG("init using kFmtUnKnown"); } else { imgInit = false; CCLOG("failed to init using kFmtUnKnown"); } if(imgInit) { std::stringstream userKeyStringStream; userKeyStringStream << "profileimage_" << m_ActorID; std::string userKeyString = userKeyStringStream.str(); CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addUIImage(img, userKeyString.c_str()); // CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addUIImage(img, "sinhyub"); if (texture != NULL) { m_ProfileImage->initWithTexture(texture); // TODO : m_ProfileImage에 파일을 로딩시키고 그것을 적절한 위치에 배치해야함 // TODO : profile image scale CCSize imageSize = m_ProfileImage->getContentSize(); const float scaleX = ProfileImageWidth / imageSize.width; const float scaleY = ProfileImageHeight / imageSize.height; m_ProfileImage->setScaleX(scaleX); m_ProfileImage->setScaleY(scaleY); } } img->release(); } else { // TODO : default image display return; } }
void AsyncLoadPlist::loadPlistAsyncCallBack(float dt) { // the image is generated in loading thread std::queue<ImageInfo*> *imagesQueue = s_pImageQueue; pthread_mutex_lock(&s_ImageInfoMutex); if (imagesQueue->empty()) { pthread_mutex_unlock(&s_ImageInfoMutex); } else { ImageInfo *pImageInfo = imagesQueue->front(); imagesQueue->pop(); pthread_mutex_unlock(&s_ImageInfoMutex); LoadStruct *pLoadStruct = pImageInfo->loadStruct; CCImage *pImage = pImageInfo->image; CCObject *target = pLoadStruct->target; SEL_CallFuncO selector = pLoadStruct->selector; std::string texturePath = pLoadStruct->texturePath; // 从texturePath中取文件名 如/../../filename.png 则filename.png std::string textureFileName = texturePath.substr(texturePath.rfind('/') + 1); CCTextureCache::sharedTextureCache()->addUIImage(pImage, textureFileName.c_str()); if (target && selector) { (target->*selector)(CCString::create(pLoadStruct->plistFileName)); target->release(); } pImage->release(); delete pLoadStruct; delete pImageInfo; --s_nAsyncRefCount; if (0 == s_nAsyncRefCount) { CCDirector::sharedDirector()->getScheduler()->unscheduleSelector(schedule_selector(AsyncLoadPlist::loadPlistAsyncCallBack), this); } } }
//------------------------------------------------------------------------- bool FKCW_UI_ProgressIndicator::initWithMessage(const string& message) { if(!CCLayerColor::initWithColor(m_tagDimColor)) { return false; } // 保存消息 m_strMessage = message; // 创建Label m_pMsgLabel = CCLabelTTF::create(m_strMessage.c_str(), "Helvetica", 28 / CC_CONTENT_SCALE_FACTOR()); // 提示器 CCImage* image = new CCImage(); image->initWithImageData((void*)s_SpinnerPng, 1043); CCTexture2D* tex = new CCTexture2D(); tex->initWithImage(image); m_pIndicator = CCSprite::createWithTexture(tex); CC_SAFE_RETAIN(m_pIndicator); image->release(); tex->release(); _RelayOut(); addChild(m_pIndicator); addChild(m_pMsgLabel); // 开启事件 setTouchEnabled(true); setTouchMode(kCCTouchesOneByOne); setTouchPriority(-MAX_INT); setKeypadEnabled(true); // 开启帧更新 scheduleUpdate(); return true; }
CCTexture2D* Util::getGrayTexture(CCTexture2D* texture){ typedef enum { RED = 0, GREEN = 1, BLUE = 2, ALPHA = 3 } PIXELS; CCSize textSize = texture->getContentSize(); CCSprite *temporarySprite = CCSprite::createWithTexture(texture); //就这么一小句搞了我半天了,不过能出来也值了 temporarySprite->setAnchorPoint(ccp(0,0)); CCRenderTexture *rt = CCRenderTexture::create(textSize.width, textSize.height); rt->begin(); temporarySprite->visit(); rt->end(); CCImage *image = rt->newCCImage(); unsigned char* pixels = image->getData(); int len = image->getDataLen(); uint32_t *p = (uint32_t *)pixels; for(int i=0;i<len;i++){ uint8_t *rgbaPixel = (uint8_t *) &p[i]; //uint32_t gray = 0.3 * rgbaPixel[RED] + 0.59 * rgbaPixel[GREEN] + 0.11 * rgbaPixel[BLUE]; uint32_t gray = 1.2*rgbaPixel[RED] + 1.0*rgbaPixel[GREEN] + 0.0*rgbaPixel[BLUE]; // set the pixels to gray rgbaPixel[RED] = gray; rgbaPixel[GREEN] = gray; rgbaPixel[BLUE] = gray; } CCTexture2D* newtexture = new CCTexture2D(); newtexture->autorelease(); newtexture->initWithImage(image); image->release(); return newtexture; }
void HelloWorld::ChangeParticle(float scale, bool isBackgroundMove, int backgroundMoveSpeed, float angle, float angleVar, int destBlendFunc, int srcBlendFunc, float duration, float emissionRate, int emiiterMode, GLbyte endColorR,GLbyte endColorG,GLbyte endColorB,GLbyte endColorA, GLbyte endColorVarR,GLbyte endColorVarG,GLbyte endColorVarB,GLbyte endColorVarA, float endRadius,float endRadiusVar, float endSize,float endSizeVar, float endSpin,float endSpinVar, float gravityX,float gravityY, bool isAutoRemoveOnFinish, float life,float lifeVar, int positionType, float positionVarX,float positionVarY, float radialAccel,float radialAccelVar, float rotatePerSecond,float rotatePerSecondVar, float sourcePositionX,float sourcePositionY, float speed,float speedVar, GLbyte startColorR,GLbyte startColorG,GLbyte startColorB,GLbyte startColorA, GLbyte startColorVarR,GLbyte startColorVarG,GLbyte startColorVarB,GLbyte startColorVarA, float startRadius,float startRadiusVar, float startSize,float startSizeVar, float startSpin,float startSpinVar, float tangentialAccel,float tangentialAccelVar, char* plistPath,char* texturePath,char* textureImageData, unsigned int totalParticles ) { if (texturePath==NULL||strlen(texturePath)==0) { return; } //mBackground->setScale(scale); CCSize size= CCDirector::sharedDirector()->getWinSize(); if (totalParticles!=mEmiiter->getTotalParticles()) { mEmiiter->removeFromParentAndCleanup(true); mEmiiter=new CCParticleSystemQuad(); mEmiiter->initWithTotalParticles(totalParticles); mEmiiter->setPosition(ccp(size.width/2,size.height/2)); mEmiiter->setTexture(CCTextureCache::sharedTextureCache()->addImage("fire.png")); mBackground->addChild(mEmiiter,1); } //if (isBackgroundMove!=mIsBackgroundMove) //{ mIsBackgroundMove=isBackgroundMove; mBackground->stopAllActions(); mBackground->setPosition(ccp(size.width/2,size.height/2)); if (mIsBackgroundMove) { CCActionInterval* move1 = CCMoveBy::create(1.0 / backgroundMoveSpeed, CCPointMake(100,0) ); CCActionInterval* move2 = CCMoveBy::create(1.0 / backgroundMoveSpeed, CCPointMake(0,100) ); CCActionInterval* move3 = CCMoveBy::create(1.0 / backgroundMoveSpeed, CCPointMake(-100,0) ); CCActionInterval* move4 = CCMoveBy::create(1.0 / backgroundMoveSpeed, CCPointMake(0,-100) ); CCFiniteTimeAction* seq = CCSequence::create(move1, move2, move3,move4,NULL); mBackground->runAction( CCRepeatForever::create((CCActionInterval*)seq) ); } //} CCTexture2D *tex = NULL; if (texturePath!=NULL) { // set not pop-up message box when load image failed bool bNotify = CCFileUtils::sharedFileUtils()->isPopupNotify(); CCFileUtils::sharedFileUtils()->setPopupNotify(false); //tex = CCTextureCache::sharedTextureCache()->addImage(texturePath); if (tex==NULL) { std::string secondPath=plistPath; secondPath+="/"; secondPath+=texturePath; tex = CCTextureCache::sharedTextureCache()->addImage(secondPath.c_str()); } // reset the value of UIImage notify CCFileUtils::sharedFileUtils()->setPopupNotify(bNotify); } if (tex) { mEmiiter->setTexture(tex); } else { unsigned char *buffer = NULL; unsigned char *deflated = NULL; CCImage *image = NULL; CCAssert(textureImageData, ""); int dataLen = strlen(textureImageData); if(dataLen != 0) { // if it fails, try to get it from the base64-gzipped data int decodeLen = base64Decode((unsigned char*)textureImageData, (unsigned int)dataLen, &buffer); CCAssert( buffer != NULL, "CCParticleSystem: error decoding textureImageData"); int deflatedLen = ZipUtils::ccInflateMemory(buffer, decodeLen, &deflated); CCAssert( deflated != NULL, "CCParticleSystem: error ungzipping textureImageData"); // For android, we should retain it in VolatileTexture::addCCImage which invoked in CCTextureCache::sharedTextureCache()->addUIImage() image = new CCImage(); bool isOK = image->initWithImageData(deflated, deflatedLen); CCAssert(isOK, "CCParticleSystem: error init image with Data"); mEmiiter->setTexture(CCTextureCache::sharedTextureCache()->addUIImage(image, texturePath)); image->release(); } CC_SAFE_DELETE_ARRAY(buffer); CC_SAFE_DELETE_ARRAY(deflated); } mEmiiter->setAngle(angle); mEmiiter->setAngleVar(angleVar); ccBlendFunc func; func.dst=destBlendFunc; func.src=srcBlendFunc; mEmiiter->setBlendFunc(func); mEmiiter->setDuration(duration); mEmiiter->setEmissionRate(emissionRate); mEmiiter->setEmitterMode(emiiterMode); ccColor4F endColor=ccc4FFromccc4B(ccc4(endColorR,endColorG,endColorB,endColorA)); mEmiiter->setEndColor(endColor); ccColor4F endColorVar=ccc4FFromccc4B(ccc4(endColorVarR,endColorVarG,endColorVarB,endColorVarA)); mEmiiter->setEndColorVar(endColorVar); if (emiiterMode==kCCParticleModeGravity ) { mEmiiter->setGravity(ccp(gravityX,gravityY)); mEmiiter->setSpeed(speed); mEmiiter->setSpeedVar(speedVar); mEmiiter->setTangentialAccel(tangentialAccel); mEmiiter->setTangentialAccelVar(tangentialAccelVar); mEmiiter->setRadialAccel(radialAccel); mEmiiter->setRadialAccelVar(radialAccelVar); } else if (emiiterMode==kCCParticleModeRadius) { mEmiiter->setStartRadius(startRadius); mEmiiter->setStartRadiusVar(startRadiusVar); mEmiiter->setEndRadius(endRadius); mEmiiter->setEndRadiusVar(endRadiusVar); mEmiiter->setRotatePerSecond(rotatePerSecond); mEmiiter->setRotatePerSecondVar(rotatePerSecondVar); } mEmiiter->setEndSize(endSize); mEmiiter->setEndSizeVar(endSizeVar); mEmiiter->setEndSpin(endSpin); mEmiiter->setEndSpinVar(endSpinVar); mEmiiter->setAutoRemoveOnFinish(isAutoRemoveOnFinish); mEmiiter->setLife(life); mEmiiter->setLifeVar(lifeVar); mEmiiter->setPositionType((tCCPositionType)positionType); mEmiiter->setPosVar(ccp(positionVarX,positionVarY)); mEmiiter->setSourcePosition(ccp(sourcePositionX,sourcePositionY)); ccColor4F startColor=ccc4FFromccc4B(ccc4(startColorR,startColorG,startColorB,startColorA)); mEmiiter->setStartColor(startColor); ccColor4F startColorVar=ccc4FFromccc4B(ccc4(startColorVarR,startColorVarG,startColorVarB,startColorVarA)); mEmiiter->setStartColorVar(startColorVar); mEmiiter->setStartSize(startSize); mEmiiter->setStartSizeVar(startSizeVar); mEmiiter->setTotalParticles(totalParticles); mEmiiter->resetSystem(); CCEGLView* eglView = CCEGLView::sharedOpenGLView(); eglView->setFrameZoomFactor(1.f * scale); }
bool CCParticleSystem::initWithDictionary(CCDictionary *dictionary, const char *dirname) { bool bRet = false; unsigned char *buffer = NULL; unsigned char *deflated = NULL; CCImage *image = NULL; do { int maxParticles = dictionary->valueForKey("maxParticles")->intValue(); // self, not super if(this->initWithTotalParticles(maxParticles)) { // angle m_fAngle = dictionary->valueForKey("angle")->floatValue(); m_fAngleVar = dictionary->valueForKey("angleVariance")->floatValue(); // duration m_fDuration = dictionary->valueForKey("duration")->floatValue(); // blend function m_tBlendFunc.src = dictionary->valueForKey("blendFuncSource")->intValue(); m_tBlendFunc.dst = dictionary->valueForKey("blendFuncDestination")->intValue(); // color m_tStartColor.r = dictionary->valueForKey("startColorRed")->floatValue(); m_tStartColor.g = dictionary->valueForKey("startColorGreen")->floatValue(); m_tStartColor.b = dictionary->valueForKey("startColorBlue")->floatValue(); m_tStartColor.a = dictionary->valueForKey("startColorAlpha")->floatValue(); m_tStartColorVar.r = dictionary->valueForKey("startColorVarianceRed")->floatValue(); m_tStartColorVar.g = dictionary->valueForKey("startColorVarianceGreen")->floatValue(); m_tStartColorVar.b = dictionary->valueForKey("startColorVarianceBlue")->floatValue(); m_tStartColorVar.a = dictionary->valueForKey("startColorVarianceAlpha")->floatValue(); m_tEndColor.r = dictionary->valueForKey("finishColorRed")->floatValue(); m_tEndColor.g = dictionary->valueForKey("finishColorGreen")->floatValue(); m_tEndColor.b = dictionary->valueForKey("finishColorBlue")->floatValue(); m_tEndColor.a = dictionary->valueForKey("finishColorAlpha")->floatValue(); m_tEndColorVar.r = dictionary->valueForKey("finishColorVarianceRed")->floatValue(); m_tEndColorVar.g = dictionary->valueForKey("finishColorVarianceGreen")->floatValue(); m_tEndColorVar.b = dictionary->valueForKey("finishColorVarianceBlue")->floatValue(); m_tEndColorVar.a = dictionary->valueForKey("finishColorVarianceAlpha")->floatValue(); // particle size m_fStartSize = dictionary->valueForKey("startParticleSize")->floatValue(); m_fStartSizeVar = dictionary->valueForKey("startParticleSizeVariance")->floatValue(); m_fEndSize = dictionary->valueForKey("finishParticleSize")->floatValue(); m_fEndSizeVar = dictionary->valueForKey("finishParticleSizeVariance")->floatValue(); // position float x = dictionary->valueForKey("sourcePositionx")->floatValue(); float y = dictionary->valueForKey("sourcePositiony")->floatValue(); this->setPosition( ccp(x,y) ); m_tPosVar.x = dictionary->valueForKey("sourcePositionVariancex")->floatValue(); m_tPosVar.y = dictionary->valueForKey("sourcePositionVariancey")->floatValue(); // Spinning m_fStartSpin = dictionary->valueForKey("rotationStart")->floatValue(); m_fStartSpinVar = dictionary->valueForKey("rotationStartVariance")->floatValue(); m_fEndSpin= dictionary->valueForKey("rotationEnd")->floatValue(); m_fEndSpinVar= dictionary->valueForKey("rotationEndVariance")->floatValue(); m_nEmitterMode = dictionary->valueForKey("emitterType")->intValue(); // Mode A: Gravity + tangential accel + radial accel if( m_nEmitterMode == kCCParticleModeGravity ) { // gravity modeA.gravity.x = dictionary->valueForKey("gravityx")->floatValue(); modeA.gravity.y = dictionary->valueForKey("gravityy")->floatValue(); // speed modeA.speed = dictionary->valueForKey("speed")->floatValue(); modeA.speedVar = dictionary->valueForKey("speedVariance")->floatValue(); // radial acceleration modeA.radialAccel = dictionary->valueForKey("radialAcceleration")->floatValue(); modeA.radialAccelVar = dictionary->valueForKey("radialAccelVariance")->floatValue(); // tangential acceleration modeA.tangentialAccel = dictionary->valueForKey("tangentialAcceleration")->floatValue(); modeA.tangentialAccelVar = dictionary->valueForKey("tangentialAccelVariance")->floatValue(); } // or Mode B: radius movement else if( m_nEmitterMode == kCCParticleModeRadius ) { modeB.startRadius = dictionary->valueForKey("maxRadius")->floatValue(); modeB.startRadiusVar = dictionary->valueForKey("maxRadiusVariance")->floatValue(); modeB.endRadius = dictionary->valueForKey("minRadius")->floatValue(); modeB.endRadiusVar = 0.0f; modeB.rotatePerSecond = dictionary->valueForKey("rotatePerSecond")->floatValue(); modeB.rotatePerSecondVar = dictionary->valueForKey("rotatePerSecondVariance")->floatValue(); } else { CCAssert( false, "Invalid emitterType in config file"); CC_BREAK_IF(true); } // life span m_fLife = dictionary->valueForKey("particleLifespan")->floatValue(); m_fLifeVar = dictionary->valueForKey("particleLifespanVariance")->floatValue(); // emission Rate m_fEmissionRate = m_uTotalParticles / m_fLife; //don't get the internal texture if a batchNode is used if (!m_pBatchNode) { // Set a compatible default for the alpha transfer m_bOpacityModifyRGB = false; // texture // Try to get the texture from the cache std::string textureName = dictionary->valueForKey("textureFileName")->getCString(); size_t rPos = textureName.rfind('/'); if (rPos != string::npos) { string textureDir = textureName.substr(0, rPos + 1); if (dirname != NULL && textureDir != dirname) { textureName = textureName.substr(rPos+1); textureName = string(dirname) + textureName; } } else { if (dirname != NULL) { textureName = string(dirname) + textureName; } } CCTexture2D *tex = NULL; if (textureName.length() > 0) { // set not pop-up message box when load image failed bool bNotify = CCFileUtils::sharedFileUtils()->isPopupNotify(); CCFileUtils::sharedFileUtils()->setPopupNotify(false); tex = CCTextureCache::sharedTextureCache()->addImage(textureName.c_str()); // reset the value of UIImage notify CCFileUtils::sharedFileUtils()->setPopupNotify(bNotify); } if (tex) { setTexture(tex); } else { const char *textureData = dictionary->valueForKey("textureImageData")->getCString(); CCAssert(textureData, ""); int dataLen = strlen(textureData); if(dataLen != 0) { // if it fails, try to get it from the base64-gzipped data int decodeLen = base64Decode((unsigned char*)textureData, (unsigned int)dataLen, &buffer); CCAssert( buffer != NULL, "CCParticleSystem: error decoding textureImageData"); CC_BREAK_IF(!buffer); int deflatedLen = ZipUtils::ccInflateMemory(buffer, decodeLen, &deflated); CCAssert( deflated != NULL, "CCParticleSystem: error ungzipping textureImageData"); CC_BREAK_IF(!deflated); // For android, we should retain it in VolatileTexture::addCCImage which invoked in CCTextureCache::sharedTextureCache()->addUIImage() image = new CCImage(); bool isOK = image->initWithImageData(deflated, deflatedLen); CCAssert(isOK, "CCParticleSystem: error init image with Data"); CC_BREAK_IF(!isOK); setTexture(CCTextureCache::sharedTextureCache()->addUIImage(image, textureName.c_str())); image->release(); } } CCAssert( this->m_pTexture != NULL, "CCParticleSystem: error loading the texture"); } bRet = true; } } while (0); CC_SAFE_DELETE_ARRAY(buffer); CC_SAFE_DELETE_ARRAY(deflated); return bRet; }
CCSprite * BSAddStrokeToLabel(cocos2d::CCLabelTTF * label, float size, cocos2d::ccColor3B color, GLubyte opacity) { CCPoint originalPos = label->getPosition(); ccColor3B originalColor = label->getColor(); GLubyte originalOpacity = label->getOpacity(); bool originalVisibility = label->isVisible(); ccBlendFunc originalBlend = label->getBlendFunc(); label->setColor(color); label->setOpacity(opacity); ccBlendFunc bf = {GL_SRC_ALPHA, GL_ONE}; label->setBlendFunc(bf); CCPoint bottomLeft = ccp(label->getTexture()->getContentSize().width * label->getAnchorPoint().x + size, label->getTexture()->getContentSize().height * label->getAnchorPoint().y + size); CCRenderTexture* rt = CCRenderTexture::create(label->getTexture()->getContentSize().width + size * 2, label->getTexture()->getContentSize().height + size * 2); /* 在原始位置绘制文字,用于镂空用 */ label->setPosition(bottomLeft); rt->begin(); label->visit(); rt->end(); CCImage * originText = rt->newCCImage(); glBlendEquation(GL_BLEND_EQUATION_ALPHA); /* 在各个方向上移动文字,重叠得到未镂空的描边 */ rt->begin(); /* Bresenham's circle algorithm */ int radis = 3 * size; for (int x = 0, y = radis, d = 3 - 2 * radis; x <= y; ++x) { float xx = x / 3.0F, yy = y / 3.0F; label->setPosition(ccp(bottomLeft.x + xx, bottomLeft.y + yy)); label->visit(); label->setPosition(ccp(bottomLeft.x - xx, bottomLeft.y + yy)); label->visit(); label->setPosition(ccp(bottomLeft.x + xx, bottomLeft.y - yy)); label->visit(); label->setPosition(ccp(bottomLeft.x - xx, bottomLeft.y - yy)); label->visit(); label->setPosition(ccp(bottomLeft.x + yy, bottomLeft.y + xx)); label->visit(); label->setPosition(ccp(bottomLeft.x - yy, bottomLeft.y + xx)); label->visit(); label->setPosition(ccp(bottomLeft.x + yy, bottomLeft.y - xx)); label->visit(); label->setPosition(ccp(bottomLeft.x - yy, bottomLeft.y - xx)); label->visit(); if (d < 0) { d = d + 4 * x + 6; } else { d = d + 4 * (x - y) + 10; y --; } } rt->end(); /* TODO: ugly workaround. rendertexture多次绘制颜色叠加,需要取色值大的那个,需要通过glBlendEquation(GL_MAX)实现。 * see http://stackoverflow.com/questions/2143690/is-it-possible-to-achieve-maxas-ad-opengl-blending */ CCImage * strokedText = rt->newCCImage(); unsigned char * pStorke = strokedText->getData(); unsigned char * pErase = originText->getData(); for (int i = 0; i < strokedText->getDataLen(); ++i) { if ((unsigned int) pErase[i * 4] != 0) { *(unsigned int *) &pStorke[i * 4] = 0; } else if ((unsigned int) pStorke[i * 4] != 0) { unsigned char * pixel = &pStorke[i * 4]; (*pixel++) = color.r; (*pixel++) = color.g; (*pixel++) = color.b; *pixel = opacity; } } originText->release(); /* 用RenderTexture构造一个Sprite,以实现支持透明度 FadeIn FadeOut */ CCTexture2D * texture2D = new CCTexture2D(); texture2D->initWithImage(strokedText); strokedText->release(); CCSprite * sprite = CCSprite::createWithTexture(texture2D); texture2D->release(); label->setPosition(originalPos); label->setColor(originalColor); label->setBlendFunc(originalBlend); label->setVisible(originalVisibility); label->setOpacity(originalOpacity); sprite->setPosition(ccp(label->getTexture()->getContentSize().width / 2, label->getTexture()->getContentSize().height / 2)); label->addChild(sprite, -1); return sprite; }