本文整理汇总了C++中CCTextureCache::addImage方法的典型用法代码示例。如果您正苦于以下问题:C++ CCTextureCache::addImage方法的具体用法?C++ CCTextureCache::addImage怎么用?C++ CCTextureCache::addImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCTextureCache
的用法示例。
在下文中一共展示了CCTextureCache::addImage方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
CCTextureCache *cache = CCTextureCache::sharedTextureCache();
//support spx
spx = CCSPXSprite::create("spx_test.sprite", cache->addImage("spx_test.png"), 0);
spx->setPosition(ccp(200,200));
addChild(spx);
//support spx3
spx3 = CCSPX3Sprite::create("spx3_test.sprite", 0, cache->addImage("spx3_test.png"),NULL);
spx3->setPosition(ccp(200, 100));
spx3->setLoopCount(-1);
addChild(spx3);
setTouchEnabled(true);
scheduleUpdate();
return true;
}
示例2: performTestsPNG
////////////////////////////////////////////////////////
//
// TextureTest
//
////////////////////////////////////////////////////////
void TextureTest::performTestsPNG(const char* filename)
{
struct timeval now;
CCTexture2D *texture;
CCTextureCache *cache = CCTextureCache::sharedTextureCache();
CCLog("RGBA 8888");
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA8888);
gettimeofday(&now, NULL);
texture = cache->addImage(filename);
if( texture )
CCLog(" ms:%f\n", calculateDeltaTime(&now) );
else
CCLog(" ERROR\n");
cache->removeTexture(texture);
//CCLog("RGBA 4444");
//CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA4444);
//gettimeofday(&now, NULL);
//texture = cache->addImage(filename);
//if( texture )
// CCLog(" ms:%f\n", calculateDeltaTime(&now) );
//else
// CCLog(" ERROR\n");
//cache->removeTexture(texture);
/* CCLog("RGBA 5551");
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGB5A1);
gettimeofday(&now, NULL);
texture = cache->addImage(filename);
if( texture )
CCLog(" ms:%f\n", calculateDeltaTime(&now) );
else
CCLog(" ERROR\n");
cache->removeTexture(texture);*/
CCLog("RGB 565");
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGB565);
gettimeofday(&now, NULL);
texture = cache->addImage(filename);
if( texture )
CCLog(" ms:%f\n", calculateDeltaTime(&now) );
else
CCLog(" ERROR\n");
cache->removeTexture(texture);
// restore default
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_Default);
}
示例3: onEnter
//------------------------------------------------------------------
//
// Arctic
//
//------------------------------------------------------------------
void AnimArctic::onEnter()
{
AnimDemo::onEnter();
// surface
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
// texture
CCTextureCache* tc = CCTextureCache::sharedTextureCache();
CCTexture2D* tex1 = tc->addImage("Files/fighterboby001.png");
CCTexture2D* tex2 = tc->addImage("Files/fighterarmor001.png");
CCTexture2D* tex3 = tc->addImage("Files/fighterweapon001.png");
// animation 1
m_sprite1 = CCArcticSprite::create("Files/fighter.aspr", 0, tex1, tex2, tex3, NULL);
m_sprite1->setLoopCount(-1);
m_sprite1->setPosition(ccp(origin.x + visibleSize.width / 2,
origin.y + visibleSize.height * 3 / 4));
m_sprite1->setUnitInterval(0.1f);
m_sprite1->setDebugDrawFrameRect(true);
m_sprite1->setDebugDrawCollisionRect(true);
addChild(m_sprite1);
// animation 2
m_sprite2 = CCArcticSprite::create("Files/fighter.aspr", 1, tex1, tex2, tex3, NULL);
m_sprite2->setLoopCount(-1);
m_sprite2->setPosition(ccp(origin.x + visibleSize.width / 2,
origin.y + visibleSize.height * 2 / 4));
m_sprite2->setUnitInterval(0.1f);
m_sprite2->setDebugDrawFrameRect(true);
m_sprite2->setDebugDrawCollisionRect(true);
addChild(m_sprite2);
// animation 3
m_sprite3 = CCArcticSprite::create("Files/fighter.aspr", 2, tex1, tex2, tex3, NULL);
m_sprite3->setLoopCount(-1);
m_sprite3->setPosition(ccp(origin.x + visibleSize.width / 2,
origin.y + visibleSize.height / 4));
m_sprite3->setUnitInterval(0.1f);
m_sprite3->setDebugDrawFrameRect(true);
m_sprite3->setDebugDrawCollisionRect(true);
addChild(m_sprite3);
scheduleUpdate();
setTouchEnabled(true);
setTouchMode(kCCTouchesOneByOne);
}
示例4: setPorperty
bool CImageWidget::setPorperty( const std::string& key,const std::string& strvalue )
{
bool ret = true;
do
{
ret = CBaseWidget::setPorperty(key,strvalue);
if (ret)
{
break;
}
if (key == CImageWidget::IMAGE_PIC)
{
CCTextureCache* pCache = CCTextureCache::sharedTextureCache();
CCTexture2D* pPic = pCache->addImage(strvalue.c_str());
this->setPic(pPic);
}
else
{
ret = false;
}
} while (0);
return ret;
}
示例5: addChild
//------------------------------------------------------------------
//
// SpriteX 2011
//
//------------------------------------------------------------------
void AnimSpriteX2011::onEnter()
{
AnimDemo::onEnter();
// surface
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
// texture
CCTextureCache* tc = CCTextureCache::sharedTextureCache();
CCTexture2D* tex = tc->addImage("Files/spx3_test.png");
// animation 1
// SpriteX doesn't support tick mode, but you can use setForceTickMode
// to enforce using tick mode. this animation use a large unit interval
// so the animation plays slow
m_sprite1 = CCSPX3Sprite::create("Files/spx3_test.sprite", 0, tex, NULL);
m_sprite1->setLoopCount(-1);
m_sprite1->setPosition(ccp(origin.x + visibleSize.width / 2,
origin.y + visibleSize.height * 7 / 8));
m_sprite1->setForceTickMode(true);
m_sprite1->setUnitInterval(0.5f);
addChild(m_sprite1);
// animation 2
m_sprite2 = CCSPX3Sprite::create("Files/spx3_test.sprite", 1, tex, NULL);
m_sprite2->setLoopCount(-1);
m_sprite2->setPosition(ccp(origin.x + visibleSize.width / 2,
origin.y + visibleSize.height * 6 / 8));
addChild(m_sprite2);
// animation 3, 反着放
m_sprite3 = CCSPX3Sprite::create("Files/spx3_test.sprite", 2, tex, NULL);
m_sprite3->setLoopCount(-1);
m_sprite3->setPosition(ccp(origin.x + visibleSize.width / 2,
origin.y + visibleSize.height * 5 / 8));
m_sprite3->setReverse(true);
addChild(m_sprite3);
// animation 4
m_sprite4 = CCSPX3Sprite::create("Files/spx3_test.sprite", 3, tex, NULL);
m_sprite4->setLoopCount(-1);
m_sprite4->setPosition(ccp(origin.x + visibleSize.width / 2,
origin.y + visibleSize.height * 4 / 8));
addChild(m_sprite4);
// animation 5, y轴倒转播放
m_sprite5 = CCSPX3Sprite::create("Files/spx3_test.sprite", 4, tex, NULL);
m_sprite5->setLoopCount(-1);
m_sprite5->setPosition(ccp(origin.x + visibleSize.width / 2,
origin.y + visibleSize.height * 3 / 8));
m_sprite5->setFlipY(true);
addChild(m_sprite5);
// animation 6
m_sprite6 = CCSPX3Sprite::create("Files/spx3_test.sprite", 5, tex, NULL);
m_sprite6->setLoopCount(-1);
m_sprite6->setPosition(ccp(origin.x + visibleSize.width / 2,
origin.y + visibleSize.height * 2 / 8));
addChild(m_sprite6);
// animation 7
m_sprite7 = CCSPX3Sprite::create("Files/spx3_test.sprite", 6, tex, NULL);
m_sprite7->setLoopCount(-1);
m_sprite7->setPosition(ccp(origin.x + visibleSize.width / 2,
origin.y + visibleSize.height / 8));
addChild(m_sprite7);
scheduleUpdate();
setTouchEnabled(true);
setTouchMode(kCCTouchesOneByOne);
}
示例6: initWithSubTest
void SubTest::initWithSubTest(int nSubTest, CCNode* p)
{
subtestNumber = nSubTest;
parent = p;
batchNode = NULL;
/*
* Tests:
* 1: 1 (32-bit) PNG sprite of 52 x 139
* 2: 1 (32-bit) PNG Batch Node using 1 sprite of 52 x 139
* 3: 1 (16-bit) PNG Batch Node using 1 sprite of 52 x 139
* 4: 1 (4-bit) PVRTC Batch Node using 1 sprite of 52 x 139
* 5: 14 (32-bit) PNG sprites of 85 x 121 each
* 6: 14 (32-bit) PNG Batch Node of 85 x 121 each
* 7: 14 (16-bit) PNG Batch Node of 85 x 121 each
* 8: 14 (4-bit) PVRTC Batch Node of 85 x 121 each
* 9: 64 (32-bit) sprites of 32 x 32 each
*10: 64 (32-bit) PNG Batch Node of 32 x 32 each
*11: 64 (16-bit) PNG Batch Node of 32 x 32 each
*12: 64 (4-bit) PVRTC Batch Node of 32 x 32 each
*/
// purge textures
CCTextureCache *mgr = CCTextureCache::sharedTextureCache();
// [mgr removeAllTextures];
mgr->removeTexture(mgr->addImage("Images/grossinis_sister1.png"));
mgr->removeTexture(mgr->addImage("Images/grossini_dance_atlas.png"));
mgr->removeTexture(mgr->addImage("Images/spritesheet1.png"));
switch ( subtestNumber)
{
case 1:
case 4:
case 7:
break;
///
case 2:
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA8888);
batchNode = CCSpriteBatchNode::create("Images/grossinis_sister1.png", 100);
p->addChild(batchNode, 0);
break;
case 3:
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA4444);
batchNode = CCSpriteBatchNode::create("Images/grossinis_sister1.png", 100);
p->addChild(batchNode, 0);
break;
///
case 5:
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA8888);
batchNode = CCSpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
p->addChild(batchNode, 0);
break;
case 6:
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA4444);
batchNode = CCSpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
p->addChild(batchNode, 0);
break;
///
case 8:
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA8888);
batchNode = CCSpriteBatchNode::create("Images/spritesheet1.png", 100);
p->addChild(batchNode, 0);
break;
case 9:
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA4444);
batchNode = CCSpriteBatchNode::create("Images/spritesheet1.png", 100);
p->addChild(batchNode, 0);
break;
default:
break;
}
if (batchNode)
{
batchNode->retain();
}
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_Default);
}
示例7: initWithString
/**
* 初始化操作
*/
bool YJTabTitle::initWithString(const char* normalImageName, const char* selectedImageName, YJTabTitleState state,
const char* displayText, const char *fontName, float fontSize, CCObject* target, SEL_CallFuncN selector)
{
if(!normalImageName)
{
return false ;
}
if(!selectedImageName)
{
return false ;
}
if(kStateNormal!=state && kStateSelected!=state)
{
return false ;
}
if(!displayText)
{
return false ;
}
if(!fontName)
{
return false ;
}
this->normalImageName = normalImageName ;
this->selectedImageName = selectedImageName ;
this->displayText = displayText ;
this->fontName = fontName ;
this->fontSize = fontSize ;
this->state = state ; // 设置状态
this->setTarget(target, selector) ; // 设置回到函数
CCTextureCache* textureCache = CCTextureCache::sharedTextureCache() ;
std::string initImageName ;
if( kStateNormal == state)
{
initImageName = normalImageName ;
}
else if(kStateSelected == state)
{
initImageName = selectedImageName ;
}
this->bgSprite = CCSprite::createWithTexture(textureCache->addImage(initImageName.c_str())) ;
this->bgSprite->setAnchorPoint(ccp(0, 0)) ;
this->bgSprite->setPosition(ccp(0, 0)) ;
this->setContentSize(this->bgSprite->getContentSize()) ;
this->addChild(this->bgSprite, 0) ;
this->label = CCLabelTTF::create(this->displayText.c_str(), this->fontName.c_str(), this->fontSize) ;
this->label->setAnchorPoint(ccp(0.5, 0.5)) ;
this->label->setPosition(ccp(this->getContentSize().width/2, this->getContentSize().height/2)) ;
this->addChild(this->label, 1) ;
return true ;
}