本文整理汇总了C++中CCTextureCache::addUIImage方法的典型用法代码示例。如果您正苦于以下问题:C++ CCTextureCache::addUIImage方法的具体用法?C++ CCTextureCache::addUIImage怎么用?C++ CCTextureCache::addUIImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCTextureCache
的用法示例。
在下文中一共展示了CCTextureCache::addUIImage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: didReceiveFile
void CCSprite::didReceiveFile(HttpRequest* r, char *data, uint32 len) {
if(r == mRequest){
CCImage* img = new CCImage;
img->initWithImageData(data, len);
CCTextureCache *cache = CCTextureCache::sharedTextureCache();
CCTexture2D* texture = cache->addUIImage(img, r->mURL->getCString());
setTextureAndSize(texture);
mRequest = NULL;
delete img;
if(mDelegate)
mDelegate->didSpriteReceiveFile(this);
}
}
示例2: setImageFromImage
void CCSprite::setImageFromImage() {
if(mWillSetImage && mWillSetImage->mPath && mCountShow <= 0) {
if(mFilePath && strcmp(mFilePath->getCString(), mWillSetImage->mPath->getCString()) )
return;
CCTextureCache *cache = CCTextureCache::sharedTextureCache();
CCTexture2D* texture = cache->addUIImage((CCImage*)mWillSetImage, mWillSetImage->mPath->getCString());
if(texture){
setTextureAndSize(texture);
if(mDelegate)
mDelegate->didSpriteReceiveFile(this);
}else{
// broken texture so delete it
s3eFileDelete(mWillSetImage->mPath->getCString());
if(mDelegate)
mDelegate->didSpriteReceiveError(this);
}
delete mWillSetImage;
mWillSetImage = NULL;
}
}
示例3: createStatsLabel
void CCDirector::createStatsLabel()
{
CCTexture2D *texture = NULL;
CCTextureCache *textureCache = CCTextureCache::sharedTextureCache();
if( m_pFPSLabel && m_pSPFLabel )
{
CC_SAFE_RELEASE_NULL(m_pFPSLabel);
CC_SAFE_RELEASE_NULL(m_pSPFLabel);
CC_SAFE_RELEASE_NULL(m_pDrawsLabel);
textureCache->removeTextureForKey("cc_fps_images");
CCFileUtils::sharedFileUtils()->purgeCachedEntries();
}
CCTexture2DPixelFormat currentFormat = CCTexture2D::defaultAlphaPixelFormat();
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA4444);
unsigned char *data = NULL;
unsigned int data_len = 0;
getFPSImageData(&data, &data_len);
CCImage* image = new CCImage();
bool isOK = image->initWithImageData(data, data_len);
if (!isOK) {
CCLOGERROR("%s", "Fails: init fps_images");
return;
}
texture = textureCache->addUIImage(image, "cc_fps_images");
CC_SAFE_RELEASE(image);
/*
We want to use an image which is stored in the file named ccFPSImage.c
for any design resolutions and all resource resolutions.
To achieve this,
Firstly, we need to ignore 'contentScaleFactor' in 'CCAtlasNode' and 'CCLabelAtlas'.
So I added a new method called 'setIgnoreContentScaleFactor' for 'CCAtlasNode',
this is not exposed to game developers, it's only used for displaying FPS now.
Secondly, the size of this image is 480*320, to display the FPS label with correct size,
a factor of design resolution ratio of 480x320 is also needed.
*/
float factor = 1.0f; // CCEGLView::sharedOpenGLView()->getDesignResolutionSize().height / 320.0f;
m_pFPSLabel = new CCLabelAtlas();
m_pFPSLabel->setIgnoreContentScaleFactor(true);
m_pFPSLabel->initWithString("00.0", texture, 12, 32 , '.');
m_pFPSLabel->setScale(factor);
m_pSPFLabel = new CCLabelAtlas();
m_pSPFLabel->setIgnoreContentScaleFactor(true);
m_pSPFLabel->initWithString("0.000", texture, 12, 32, '.');
m_pSPFLabel->setScale(factor);
m_pDrawsLabel = new CCLabelAtlas();
m_pDrawsLabel->setIgnoreContentScaleFactor(true);
m_pDrawsLabel->initWithString("000", texture, 12, 32, '.');
m_pDrawsLabel->setScale(factor);
CCTexture2D::setDefaultAlphaPixelFormat(currentFormat);
m_pDrawsLabel->setPosition(ccpAdd(ccp(0, 34*factor), CC_DIRECTOR_STATS_POSITION));
m_pSPFLabel->setPosition(ccpAdd(ccp(0, 17*factor), CC_DIRECTOR_STATS_POSITION));
m_pFPSLabel->setPosition(CC_DIRECTOR_STATS_POSITION);
}