本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}