コード例 #1
0
void UnloadableSpriteNode::loadedTexture(CCObject* obj)
{
    CCTexture2D* aTex = (CCTexture2D*)obj;
    if (aTex==NULL || aTex->retainCount()<=0) {
        loading = false;
        return;
    }
	aTex->setAntiAliasTexParameters();
	
	//create sprite, position it and at to self
    drawing = true;
    
    this->_sprite = new CCSprite;
    this->_sprite->initWithTexture(aTex);

	this->_sprite->setAnchorPoint(ccp(0,0));
	this->_sprite->setPosition(ccp(0,0));
    
	// fill our activeRect fully with sprite (stretch if needed)
	this->_sprite->setScaleX(this->_activeRect.size.width / this->_sprite->getContentSize().width);
	this->_sprite->setScaleY(this->_activeRect.size.height / this->_sprite->getContentSize().height);
    
    loading = false;
    drawing = false;
}
コード例 #2
0
ファイル: XSpriteBatchNode.cpp プロジェクト: SLS-ACT/TeamTest
void XSpriteBatchNode::setAntiAliasTexParameters()
{
	XFUNC_START();
	if (m_pobTextureAtlas)
	{
		CCTexture2D* tex = m_pobTextureAtlas->getTexture();
		if (tex)
		{
			tex->setAntiAliasTexParameters();
		}
	}
	
	XFUNC_END();
}
コード例 #3
0
ファイル: XSpriteBatchNode.cpp プロジェクト: SLS-ACT/TeamTest
void XSpriteBatchNode::ResHandle( long lParam )
{
	XFUNC_START();
	do 
	{
		const char* szPath = NULL;
		XResType* pResType = XResLoader::Instance().GetResByID(lParam);
		if (!pResType)
		{
			break;
		}
		CCTexture2D* pTex;
		if (XResType::ePng == pResType->GetType())
		{
			XResPNG* pRes = dynamic_cast<XResPNG*>(pResType);
			if (!pRes)
			{
				break;
			}
			XTexture2D* &pCTex = pRes->m_pTexture;
			if (!pCTex)
			{
				break;
			}
			if (pRes->m_pImage)
			{
				bool bRes = XTextureCache::Instance().InitTexture(pRes->m_szPath, pRes->m_pImage, pCTex);
				if (!bRes)
				{
					break;
				}
				// Òѽ«Í¼Æ¬×ª»¯ÎªÌùͼ£¬É¾³ýͼƬ£¬ÊÍ·ÅÄÚ´æ¡£
				delete pRes->m_pImage;
				pRes->m_pImage = NULL;
			}
			pTex = pCTex;
			szPath = pRes->m_szPath;
		}
		else
		{
			break;
			//// ѹËõÎÆÀí
			//XResCompressed* pRes = dynamic_cast<XResCompressed*>(pResType);
			//if (!pRes)
			//{
			//	break;
			//}
			//XTexture2D* &pXTex = pRes->m_pTexture;
			//if (!pXTex)
			//{
			//	break;
			//}
			//if (!pRes->m_byTexInited)
			//{
			//	bool bRes = XTextureCache::Instance().InitTexture(pRes->m_szPath, pXTex, pRes->m_pTexAlpha);
			//	if (!bRes)
			//	{
			//		break;
			//	}
			//	pRes->m_byTexInited = 0xFF;
			//}
			//if (pRes->m_pTexAlpha)
			//{
			//	m_pTexKtxAlpha = pRes->m_pTexAlpha;
			//	m_pTexKtxAlpha->retain();
			//	m_pShaderKTX = XShader::GetShader(this, XShader::eETC);
			//}			
			//pTex = pXTex;
			//szPath = pRes->m_szPath;
		}
		if(_byAntiAlias)
			pTex->setAntiAliasTexParameters();
		else
			pTex->setAliasTexParameters();
		// ´´½¨¾«Áé
		XSBNChildInfo* pHead = _stChildren._pHead;
		XSBNChildInfo* pUsed;
		int nPos = 0;
		while(pHead)
		{
			pUsed = pHead;
			pHead = pHead->_pNext;
			XSprite* pSprite = XSprite::createWithTexture(pTex, pUsed->stRect, _byAntiAlias);
			if (!pSprite)
			{
				CCLOG("XSprite::createWithTexture failed!");
				continue;
			}
			if (pUsed->byFlipX)
			{
				pSprite->setFlipX(true);
			}
			pSprite->setAnchorPoint(ccp(0.f, 0.f));
			pSprite->setPosition(ccp(pUsed->fPosX, pUsed->fPosY));
			pSprite->setScaleY(_fChildrenScaleY);
			CCSpriteBatchNode::addChild(pSprite, pSprite->getZOrder(), nPos++);
			XMP_RELEASE(XSBNChildInfo, pUsed);
		}
		_stChildren.Clear();
		_bResLoaded = true;
		if(_bCleanUpThread)
			cleanup();

		//static unsigned long dwRes = 0;
		//CCLOG("XSpriteBatchNode::ResHandle [%d] %s", dwRes++, szPath);

		return;
	} while (0);
	_bResLoaded = false;
	OnRelease();
	CCLOG("[ERROR]XSpriteBatchNode::ResHandle load res failed.");
	XFUNC_END();
}
コード例 #4
0
// Helper
bool CCLabelTTF::updateTexture()
{
	//if(this->isFlipY())
	//	this->setFlipY(false);
    CCTexture2D *tex;
    tex = new CCTexture2D();
    
    if (!tex)
        return false;

    #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    
        ccFontDefinition texDef = _prepareTextDefinition(true);
        tex->initWithString( m_string.c_str(), &texDef );
    
    #else
    
        tex->initWithString( m_string.c_str(),
                            m_pFontName->c_str(),
                            m_fFontSize * CC_CONTENT_SCALE_FACTOR(),
                            CC_SIZE_POINTS_TO_PIXELS(m_tDimensions),
                            m_hAlignment,
                            m_vAlignment);
    
    #endif
    
    // set the texture
    this->setTexture(tex);
    // release it
    tex->release();
    
    // set the size in the sprite
    CCRect rect =CCRectZero;
    rect.size   = m_pobTexture->getContentSize();
    this->setTextureRect(rect);

	/***************************给文字描黑边begin*********************************/

	CCPoint prePos = this->getPosition();
	ccColor3B color1 = this->getColor();
    float strokeValue = 2;
	CCSize textureSize = this->getContentSize();
    textureSize.width += 2 * strokeValue;
    textureSize.height += 2 * strokeValue;
     
    /* 监测OpenGl的错误状态 */
    glGetError();
     
    /* 创建一张纹理画布 */
    CCRenderTexture *rt = CCRenderTexture::create(textureSize.width, textureSize.height);
    if(!rt)
    {
        CCLog("create render texture failed !!!!");
        //addChild(label);
        return 0;
    }
     
    /* 设置描边的颜色 */
    this->setColor(ccBLACK);
     
    /* 
     *拿到源文字的混色机制,存储以备恢复,并设置新的目标混色机制
     *混色机制设为:源颜色透明度(影响亮度)和目标颜色(影响颜色)
     */
    ccBlendFunc originalBlend = this->getBlendFunc();
    ccBlendFunc func = { GL_SRC_ALPHA, GL_ONE};
    this->setBlendFunc(func);
     CCPoint anchPoint = this->getAnchorPoint();
	 
    /* 这是自定义的一些调整,倾斜了一点 */
    this->setAnchorPoint(CCPoint(0.5, 0.5));
    //label->setRotationX(15);
     
    /* 张开画布,开始绘画 */
    rt->begin();
	this->setFlipY(true);
    for(int i = 0; i < 360; i += 5)//每变化5度绘制一张
    {
        float r = CC_DEGREES_TO_RADIANS(i); //度数格式的转换
        this->setPosition(CCPoint(textureSize.width * 0.5f + sin(r) * strokeValue,textureSize.height * 0.5f + cos(r) * strokeValue));
 
        /* CCRenderTexture的用法,在begin和end之间visit的纹理,都会画在CCRenderTexture里面 */
        this->visit();//画了一次该label
    }
 
    /* 恢复原始的label并绘制在最上层 */
    this->setColor(color1);
    this->setBlendFunc(originalBlend);
    this->setPosition(CCPoint(textureSize.width * 0.5f, textureSize.height * 0.5f));
    this->visit();
	this->setFlipY(false);
    /* 在画布上绘制结束,此时会生成一张纹理 */
    rt->end();
     
    /* 取出生成的纹理,添加抗锯齿打磨,并返回 */
    CCTexture2D *texture = rt->getSprite()->getTexture();
    texture->setAntiAliasTexParameters();// setAliasTexParameters();
	this->setTexture(texture);
	// release it
	rt->release();

	//set the size in the sprite
		rect =CCRectZero;
	rect.size   = m_pobTexture->getContentSize();

	//this->setFlipY(true);
	//this->setFlipX(true);
	this->setTextureRect(rect);
	//if(!this->isFlipY())
	//	this->setFlipY(true);
	this->setAnchorPoint(anchPoint);
	this->setColor(color1);
	this->setPosition(prePos);

	/***************************给文字描黑边end*********************************/
    //ok
    return true;
}