当前位置: 首页>>代码示例>>C++>>正文


C++ CCTexture2D::release方法代码示例

本文整理汇总了C++中CCTexture2D::release方法的典型用法代码示例。如果您正苦于以下问题:C++ CCTexture2D::release方法的具体用法?C++ CCTexture2D::release怎么用?C++ CCTexture2D::release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CCTexture2D的用法示例。


在下文中一共展示了CCTexture2D::release方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: addImage

CCTexture2D* MapTexturePool::addImage(const char* path, bool keep)
{
	NDAsssert(path != NULL);

	CCTexture2D* pkTexture = NULL;

	// MUTEX:
	// Needed since addImageAsync calls this method from a different thread

	pkTexture = (CCTexture2D*)m_pkDict->objectForKey(path);

	if (!pkTexture)
	{
		CCImage image;
		if (image.initWithImageFile(path))
		{
			//todo
			//tex = [ [CCTexture2D alloc] initWithImage:image keepData:keep];
		}

		if (pkTexture)
		{
			m_pkDict->setObject(pkTexture, path);
			pkTexture->release();
		}
	}

	return pkTexture;
}
开发者ID:boyjimeking,项目名称:HHHH,代码行数:29,代码来源:NDMapData.cpp

示例2: setString

	void CCLabelTTF::setString(const char *label)
	{
        if (strlen(label)==0)
        {
            return;
        }

		m_sString = string(label);
        
		CCTexture2D *texture;
		if( CGSize::CGSizeEqualToSize( m_tDimensions, CGSizeZero ) )
		{
			texture = new CCTexture2D();
			texture->initWithString(label, m_sFontName.c_str(), m_fFontSize);
		}
		else
		{
			texture = new CCTexture2D();
			texture->initWithString(label, m_tDimensions, m_eAlignment, m_sFontName.c_str(), m_fFontSize);
		}
		this->setTexture(texture);
		texture->release();

        CGRect rect = CGRectZero;
		rect.size = m_pobTexture->getContentSize();
		this->setTextureRect(rect);
	}
开发者ID:geniikw,项目名称:myFirst2DGame,代码行数:27,代码来源:CCLabelTTF.cpp

示例3: SetTexture

void SuperAnimSprite::SetTexture(CCTexture2D *theTexture, CCRect theTextureRect)
{
	if (theTexture == NULL)
	{
		return;
	}
	
	if (mTexture != NULL)
	{
		mTexture->release();
		mTexture = NULL;
	}
	
	// retain this texture in case removed by removeUnusedTextures();
	theTexture->retain();
	mTexture = theTexture;
	
	// Set Texture coordinates
	CCRect theTexturePixelRect = CC_RECT_POINTS_TO_PIXELS(theTextureRect);
	float aTextureWidth = (float)mTexture->getPixelsWide();
	float aTextureHeight = (float)mTexture->getPixelsHigh();
	
	float aLeft, aRight, aTop, aBottom;
	aLeft = theTexturePixelRect.origin.x / aTextureWidth;
	aRight = (theTexturePixelRect.origin.x + theTexturePixelRect.size.width) / aTextureWidth;
	aTop = theTexturePixelRect.origin.y / aTextureHeight;
	aBottom = (theTexturePixelRect.origin.y + theTexturePixelRect.size.height) / aTextureHeight;
	
	mQuad.bl.texCoords.u = aLeft;
	mQuad.bl.texCoords.v = aBottom;
	mQuad.br.texCoords.u = aRight;
	mQuad.br.texCoords.v = aBottom;
	mQuad.tl.texCoords.u = aLeft;
	mQuad.tl.texCoords.v = aTop;
	mQuad.tr.texCoords.u = aRight;
	mQuad.tr.texCoords.v = aTop;
	
	// Set position
	//float x1 = 0;
	//float y1 = 0;
	//float x2 = x1 + theTextureRect.size.width;
	//float y2 = y1 + theTextureRect.size.height;
	
	float x1 = theTexturePixelRect.size.width * -0.5f;
	float y1 = theTexturePixelRect.size.height * -0.5f;
	float x2 = theTexturePixelRect.size.width * 0.5f;
	float y2 = theTexturePixelRect.size.height * 0.5f;
	
	mQuad.bl.vertices = vertex3(x1, y1, 0);
	mQuad.br.vertices = vertex3(x2, y1, 0);
	mQuad.tl.vertices = vertex3(x1, y2, 0);
	mQuad.tr.vertices = vertex3(x2, y2, 0);
	
	// Set color
	ccColor4B aDefaultColor = {255, 255, 255, 255};
	mQuad.bl.colors = aDefaultColor;
	mQuad.br.colors = aDefaultColor;
	mQuad.tl.colors = aDefaultColor;
	mQuad.tr.colors = aDefaultColor;
}
开发者ID:xiangry,项目名称:cocos2dx-classical,代码行数:60,代码来源:CCSuperAnim.cpp

示例4: updateTexture

// Helper
bool CCLabelTTF::updateTexture()
{
    CCTexture2D *tex;
    
    // let system compute label's width or height when its value is 0
    // refer to cocos2d-x issue #1430
    tex = new CCTexture2D();
    if (!tex)
    {
		return false;
    }
    
    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);
	
    this->setTexture(tex);
    tex->release();
	
	CCRect rect = CCRectZero;
    rect.size = m_pobTexture->getContentSize();
    this->setTextureRect(rect);

    return true;
}
开发者ID:HotWordland,项目名称:cocos2d-x,代码行数:29,代码来源:CCLabelTTF.cpp

示例5: setString

	void CCLabelTTF::setString(const char *label)
	{
        if (m_pString)
        {
            delete m_pString;
            m_pString = NULL;
        }
        m_pString = new std::string(label);

		CCTexture2D *texture;
		if( CCSize::CCSizeEqualToSize( m_tDimensions, CCSizeZero ) )
		{
			texture = new CCTexture2D();
			texture->initWithString(label, m_pFontName->c_str(), m_fFontSize);
		}
		else
		{
			texture = new CCTexture2D();
			texture->initWithString(label, m_tDimensions, m_eAlignment, m_pFontName->c_str(), m_fFontSize);
		}
		this->setTexture(texture);
		texture->release();

        CCRect rect = CCRectZero;
		rect.size = m_pobTexture->getContentSize();
		this->setTextureRect(rect);
	}
开发者ID:tungt84,项目名称:cocos2d-blackberry,代码行数:27,代码来源:CCLabelTTF.cpp

示例6: updateTexture

// Helper
void CCLabelTTF::updateTexture()
{
    CCTexture2D *tex;
    if (m_tDimensions.width == 0 || m_tDimensions.height == 0)
    {
        tex = new CCTexture2D();
        tex->initWithString(m_string.c_str(), m_pFontName->c_str(), m_fFontSize * CC_CONTENT_SCALE_FACTOR()) ;
    }
    else
    {
        tex = new CCTexture2D();
        tex->initWithString(m_string.c_str(),
                            CC_SIZE_POINTS_TO_PIXELS(m_tDimensions),
                            m_hAlignment,
                            m_vAlignment,
                            m_pFontName->c_str(),
                            m_fFontSize * CC_CONTENT_SCALE_FACTOR());
    }

    // iPad ?
    //if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
    if (CCApplication::sharedApplication().isIpad())
    {
        if (CC_CONTENT_SCALE_FACTOR() == 2)
        {
            tex->setResolutionType(kCCResolutioniPadRetinaDisplay);
        }
        else
        {
            tex->setResolutionType(kCCResolutioniPad);
        }
    }
    // iPhone ?
    else
    {
        if (CC_CONTENT_SCALE_FACTOR() == 2)
        {
            tex->setResolutionType(kCCResolutioniPhoneRetinaDisplay);
        }
        else
        {
            tex->setResolutionType(kCCResolutioniPhone);
        }
    }

    this->setTexture(tex);
    tex->release();

    CCRect rect = CCRectZero;
    rect.size = m_pobTexture->getContentSize();
    this->setTextureRect(rect);
}
开发者ID:rohankuruvilla,项目名称:cocos2dx-watermelon-ios,代码行数:53,代码来源:CCLabelTTF.cpp

示例7: onEnter

void EaseSpriteDemo::onEnter()
{
	CCLayer::onEnter();

	// Example:
	// You can create a sprite using a Texture2D
	CCTexture2D* tex = new CCTexture2D();
	UIImage* pImage = new UIImage();
	
	if(pImage->initWithContentsOfFile(CCFileUtils::fullPathFromRelativePath(s_pPathGrossini)))
	{
		tex->initWithImage(pImage);
		m_grossini = CCSprite::spriteWithTexture(tex); 
		m_grossini->retain();

	}

	tex->release();
	delete pImage;
	
	// Example:
	// Or you can create an sprite using a filename. PNG and BMP files are supported. Probably TIFF too
	m_tamara = CCSprite::spriteWithFile(s_pPathSister1); m_tamara->retain();
	m_kathia = CCSprite::spriteWithFile(s_pPathSister2); m_kathia->retain();
	
	addChild( m_grossini, 3);
	addChild( m_kathia, 2);
	addChild( m_tamara, 1);

	CGSize s = CCDirector::sharedDirector()->getWinSize();

	m_grossini->setPosition( CGPointMake(60, 50) );
	m_kathia->setPosition( CGPointMake(60, 150) );
	m_tamara->setPosition( CGPointMake(60, 250) );

	CCLabelTTF* label = CCLabelTTF::labelWithString(title().c_str(), "Arial", 32);
	addChild(label);
	label->setPosition( CGPointMake(s.width/2, s.height-50) );

	CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(EaseSpriteDemo::backCallback) );
	CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(EaseSpriteDemo::restartCallback) );
	CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(EaseSpriteDemo::nextCallback) );

	CCMenu *menu = CCMenu::menuWithItems(item1, item2, item3, NULL);

	menu->setPosition( CGPointZero );
	item1->setPosition( CGPointMake( s.width/2 - 100,30) );
	item2->setPosition( CGPointMake( s.width/2, 30) );
	item3->setPosition( CGPointMake( s.width/2 + 100,30) );
	
	addChild(menu, 1);	
}
开发者ID:valentinvit,项目名称:cocos2d-x,代码行数:52,代码来源:EaseActionsTest.cpp

示例8: setString

void CCLabelTTF::setString(const char *label)
{
    if (m_pString)
    {
        delete m_pString;
        m_pString = NULL;
    }
    m_pString = new std::string(label);
    
    CCTexture2D *texture;
    if( CCSize::CCSizeEqualToSize( m_tDimensions, CCSizeZero ) )
    {
        texture = new CCTexture2D();
        texture->initWithString(label, m_pFontName->c_str(), m_fFontSize);
    }
    else
    {
        texture = new CCTexture2D();
        texture->initWithString(label, m_tDimensions, m_eAlignment, m_pFontName->c_str(), m_fFontSize);
    }

// TODO
// #ifdef __CC_PLATFORM_IOS
//     // iPad ?
//     if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
//         if( CC_CONTENT_SCALE_FACTOR() == 2 )
//             [tex setResolutionType:kCCResolutioniPadRetinaDisplay];
//         else
//             [tex setResolutionType:kCCResolutioniPad];
//     }
//     // iPhone ?
//     else
//     {
//         if( CC_CONTENT_SCALE_FACTOR() == 2 )
//             [tex setResolutionType:kCCResolutioniPhoneRetinaDisplay];
//         else
//             [tex setResolutionType:kCCResolutioniPhone];
//     }
// #end
    this->setTexture(texture);
    texture->release();

    CCRect rect = CCRectZero;
    rect.size = m_pobTexture->getContentSize();
    this->setTextureRect(rect);
}
开发者ID:Aaron-Teng,项目名称:AnalyticX,代码行数:46,代码来源:CCLabelTTF.cpp

示例9: CreateWhiteBack

	void UITextInputField::CreateWhiteBack()
	{
		if(m_pWhiteBack != NULL)
		{
			m_pWhiteBack->removeFromParentAndCleanup(true);
			m_pWhiteBack = NULL;
		}

		if(m_pTextInputField == NULL)
		{
			return;
		}

		CCSize dimension = m_pTextInputField->getDimensions();
		int dimensionWidth = dimension.width;
		int dimensionHeight = dimension.height;

		if(dimensionWidth != 0 && dimensionHeight != 0)
		{
			int *pixels = new int[(dimensionWidth + 8) * (dimensionHeight + 8)];
			for (int i=0; i<dimensionWidth+8; ++i) {
				for (int j=0; j<dimensionHeight+8; ++j) {
					//pixels[i][j] = 0xffffffff;
					pixels[i*4+j] = 0xffffffff;
				}
			}

			CCTexture2D *texture = new CCTexture2D();
			texture->initWithData(pixels,
				kCCTexture2DPixelFormat_RGB888,
				1,
				1,
				CCSizeMake(dimensionWidth + 8, dimensionHeight + 8)
				);

			delete[] pixels;

			m_pWhiteBack = CCSprite::createWithTexture(texture);
			texture->release();
		}
	}
开发者ID:niuzb,项目名称:hellopet,代码行数:41,代码来源:UITextInputField.cpp

示例10: initWithMessage

//-------------------------------------------------------------------------
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;
}
开发者ID:duzhi5368,项目名称:FKCocos2dxWrapper_2.x,代码行数:41,代码来源:FKCW_UI_ProgressIndicator.cpp

示例11: GetTextSize

CCSize CCtrlEdit::GetTextSize(const char * text)
{
	CCSize textSize(0.0f,0.0f);

	if (NULL == text)
	{
		return textSize;
	}

	do
	{
		CCTexture2D *tex = new CCTexture2D();
		CC_BREAK_IF(!tex);

		float fContentScaleFactor= CCDirector::sharedDirector()->getContentScaleFactor();
		bool bRet = tex->initWithString( text,
			m_strFontName.c_str(),
			m_nFontSize * fContentScaleFactor,
			CCSizeZero,
			m_pTextField->getHorizontalAlignment(),
			m_pTextField->getVerticalAlignment());

		if (bRet)
		{
			float fOffsetX = tex->getPixelsWide();
			fOffsetX /= fContentScaleFactor;
			textSize.width += fOffsetX;

			float fOffsetY = tex->getPixelsHigh();
			fOffsetY /= fContentScaleFactor;
			textSize.height += fOffsetY;
		}

		tex->release();
	}while(false);

	return textSize;
}
开发者ID:twkevin,项目名称:ddz,代码行数:38,代码来源:CtrlEdit.cpp

示例12: updateTexture

// Helper
bool CCLabelTTF::updateTexture()
{
    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);
    
    //ok
    return true;
}
开发者ID:caoguoping,项目名称:warCraft,代码行数:38,代码来源:CCLabelTTF.cpp

示例13: initWithSize

	bool CCGridBase::initWithSize(ccGridSize gridSize)
	{
    	CCDirector *pDirector = CCDirector::sharedDirector();
		CGSize s = pDirector->getWinSizeInPixels();
		
		unsigned int POTWide = ccNextPOT((unsigned int)s.width);
		unsigned int POTHigh = ccNextPOT((unsigned int)s.height);

		// on mac, it use kCCTexture2DPixelFormat_RGBA8888
		CCTexture2DPixelFormat format = kCCTexture2DPixelFormat_RGBA8888;

		void *data = calloc((int)(POTWide * POTHigh * 4), 1);
		if (! data)
		{
			CCLOG("cocos2d: CCGrid: not enough memory.");
			this->release();
			return false;
		}

		CCTexture2D *pTexture = new CCTexture2D();
		pTexture->initWithData(data, format, POTWide, POTHigh, s);

		free(data);

		if (! pTexture)
		{
			CCLOG("cocos2d: CCGrid: error creating texture");
			delete this;
			return false;
		}

		initWithSize(gridSize, pTexture, false);

		pTexture->release();

		return true;
	}
开发者ID:BigHand,项目名称:cocos2d-x,代码行数:37,代码来源:CCGrid_mac.cpp

示例14: initWithSize

bool CCGridBase::initWithSize(const ccGridSize& gridSize)
{
	CCDirector *pDirector = CCDirector::sharedDirector();
	CCSize s = pDirector->getWinSizeInPixels();

	unsigned int POTWide = (unsigned int) s.width;
	unsigned int POTHigh = (unsigned int) s.height;

	bool needPOT = !g_Render->isRenderTargetNPOTSupported();

	if (needPOT)
	{
		POTWide = PixelFormat::calcNextPot(POTWide);
		POTHigh = PixelFormat::calcNextPot(POTHigh);
	}

	// we only use rgba8888
	CCTexture2DPixelFormat format = kCCTexture2DPixelFormat_RGBA8888;

	CCTexture2D *pTexture = new CCTexture2D();

	if (! pTexture)
	{
		CCLOG("cocos2d: CCGrid: error creating texture");
		delete this;
		return false;
	}

	pTexture->initWithTexture(
		new GLESTexture(POTWide, POTHigh, CCTexture2D::ToNitPixelFormat(format, false)));

	initWithSize(gridSize, pTexture, false);

	pTexture->release();

	return true;
}
开发者ID:noriter,项目名称:nit,代码行数:37,代码来源:CCGrid.cpp

示例15: onEnter

void ActionsDemo::onEnter()
{
    CCLayer::onEnter();

    // Example:
    // You can create a sprite using a Texture2D
    CCTexture2D *tex = new CCTexture2D();
    UIImage* pImage = new UIImage();
    std::string fullpath( CCFileUtils::fullPathFromRelativePath(s_pPathGrossini));
    pImage->initWithContentsOfFile(fullpath);
    tex->initWithImage( pImage );
    m_grossini = CCSprite::spriteWithTexture(tex);
    m_grossini->retain();
    delete pImage;
    tex->release();

    // Example:
    // Or you can create an sprite using a filename. only PNG is supported now. Probably TIFF too
    m_tamara = CCSprite::spriteWithFile(s_pPathSister1);
    m_tamara->retain();

    m_kathia = CCSprite::spriteWithFile(s_pPathSister2);
    m_kathia->retain();

    addChild(m_grossini, 1);
    addChild(m_tamara, 2);
    addChild(m_kathia, 3);

    CGSize s = CCDirector::sharedDirector()->getWinSize();

    m_grossini->setPosition( CGPointMake(s.width/2, s.height/3));
    m_tamara->setPosition( CGPointMake(s.width/2, 2*s.height/3));
    m_kathia->setPosition( CGPointMake(s.width/2, s.height/2));

    // add title and subtitle
    std::string str = title();
    const char * pTitle = str.c_str();
    CCLabelTTF* label = CCLabelTTF::labelWithString(pTitle, "Arial", 18);
    addChild(label, 1);
    label->setPosition( CGPointMake(s.width/2, s.height - 30) );

    std::string strSubtitle = subtitle();
    if( ! strSubtitle.empty() )
    {
        CCLabelTTF* l = CCLabelTTF::labelWithString(strSubtitle.c_str(), "Thonburi", 22);
        addChild(l, 1);
        l->setPosition( CGPointMake(s.width/2, s.height - 60) );
    }

    // add menu
    CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(ActionsDemo::backCallback) );
    CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(ActionsDemo::restartCallback) );
    CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(ActionsDemo::nextCallback) );

    CCMenu *menu = CCMenu::menuWithItems(item1, item2, item3, NULL);

    menu->setPosition( CGPointZero );
    item1->setPosition( CGPointMake( s.width/2 - 100,30) );
    item2->setPosition( CGPointMake( s.width/2, 30) );
    item3->setPosition( CGPointMake( s.width/2 + 100,30) );

    addChild(menu, 1);
}
开发者ID:shootan,项目名称:Terraria,代码行数:63,代码来源:ActionsTest.cpp


注:本文中的CCTexture2D::release方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。