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


C++ CCTextureCache类代码示例

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


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

示例1: updateInfo

void* LoadingLayer::updateInfo(void* args)
{

    // 开线程加载plist文件,将plist加载到CCSpriteFrameCache
    CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
    CCTextureCache* teCache = CCTextureCache::sharedTextureCache();
    for (int i=0; i<m_staticYPlist->count() * 0.5; i++)
    {
        const char* m_pngFullPath = ((CCString* )m_staticYPlist->objectAtIndex(i))->getCString();
        const char* m_plistFullPath = ((CCString* )m_staticYPlist->objectAtIndex(i + m_staticYPlist->count() * 0.5))->getCString();
//        CCLog("m_pngFullPath:%s", m_pngFullPath);
//        CCLog("m_plistFullPath:%s", m_plistFullPath);
        
        CCTexture2D* texture = teCache->textureForKey(m_pngFullPath);
        cache->addSpriteFramesWithFile(m_plistFullPath, texture);
        // 删除纹理
        teCache->removeTextureForKey(m_pngFullPath);
    }
    // 可以异步加载数据 m_target为空,就跳过
    if (m_instance->m_target)
    {
        if (m_instance->m_callFuncData)
        {
            (m_instance->m_target->*m_instance->m_callFuncData)();
        }
        
    }
    m_instance->isOver = true;
//    m_taxiBus->runAction(CCSequence::create(
//                                            CCMoveTo::create(0.7, ccp(m_moveLength, m_taxiBus->getPosition().y)),
//                                            CCCallFunc::create(m_instance, callfunc_selector(LoadingLayer::loadingSuccessful)),
//                                            NULL));

    return NULL;
}
开发者ID:jtly1985,项目名称:MytestGitHub,代码行数:35,代码来源:LoadingLayer.cpp

示例2: 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;
}
开发者ID:charleybin,项目名称:spx4cocos2dx,代码行数:27,代码来源:HelloWorldScene.cpp

示例3: 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;
}
开发者ID:tonyhu1983,项目名称:Cobra2d,代码行数:25,代码来源:CImageWidget.cpp

示例4: onEnter

//------------------------------------------------------------------
//
// Clip Mapping (Aurora GT)
//
//------------------------------------------------------------------
void AnimClipMappingAuroraGT::onEnter()
{
    AnimDemo::onEnter();
    
    // surface
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
    
    // texture
    CCTextureCache* tc = CCTextureCache::sharedTextureCache();
    CCTexture2D* tex = tc->addImage("Files/prince.png");
    
    // animation 1
    m_sprite1 = CCAuroraSprite::create("Files/prince.bsprite", 78, tex, NULL);
    m_sprite1->setLoopCount(-1);
    m_sprite1->setPosition(ccp(origin.x + visibleSize.width / 2,
                               origin.y + visibleSize.height / 2));
    m_sprite1->setUnitInterval(0.1f);
    m_sprite1->setDebugDrawFrameRect(true);
    m_sprite1->setDebugDrawCollisionRect(true);
    addChild(m_sprite1);
    
    // create clip mapping and add them to sprite
    CCAFCClipMapping* mapping = CCAFCClipMapping::createWithAuroraGT(1, "Files/prince_m00.mmp");
    m_sprite1->addClipMapping(mapping);
    mapping = CCAFCClipMapping::createWithAuroraGT(2, "Files/prince_m01.mmp");
    m_sprite1->addClipMapping(mapping);
    mapping = CCAFCClipMapping::createWithAuroraGT(3, "Files/prince_m02.mmp");
    m_sprite1->addClipMapping(mapping);
    mapping = CCAFCClipMapping::createWithAuroraGT(4, "Files/prince_m03.mmp");
    m_sprite1->addClipMapping(mapping);
    mapping = CCAFCClipMapping::createWithAuroraGT(5, "Files/prince_m04.mmp");
    m_sprite1->addClipMapping(mapping);
    mapping = CCAFCClipMapping::createWithAuroraGT(6, "Files/prince_m05.mmp");
    m_sprite1->addClipMapping(mapping);
    mapping = CCAFCClipMapping::createWithAuroraGT(7, "Files/prince_m06.mmp");
    m_sprite1->addClipMapping(mapping);
    mapping = CCAFCClipMapping::createWithAuroraGT(8, "Files/prince_m07.mmp");
    m_sprite1->addClipMapping(mapping);
    
    CCLabelTTF* label = CCLabelTTF::create("Switch Clip Mapping", "Helvetica", 16);
    CCMenuItemLabel* item = CCMenuItemLabel::create(label,
                                                    this,
                                                    menu_selector(AnimClipMappingAuroraGT::onSwitchClipMapping));
    item->setPosition(ccp(origin.x + visibleSize.width / 2,
                          origin.y + visibleSize.height / 7));
    CCMenu* menu = CCMenu::create(item, NULL);
    menu->setPosition(CCPointZero);
    addChild(menu);
    
    scheduleUpdate();
    
    setTouchEnabled(true);
    setTouchMode(kCCTouchesOneByOne);
}
开发者ID:Cocos2d-x-vn,项目名称:cocos2dx-better,代码行数:60,代码来源:AnimTest.cpp

示例5: releaseUI

/* 释放本技能相关 ui 资源 */
void SkillItem::releaseUI() {
    CCTextureCache* pTextureCache = CCTextureCache::sharedTextureCache();
    CCSpriteFrameCache* pSpriteFrameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
    
    // 获取大文件名
    
    std::string c = getC();
    std::string pvrFile = c + ".pvr.ccz";
    std::string plistFile = c + ".plist";
    
    pTextureCache->removeTextureForKey(pvrFile.c_str());
    pSpriteFrameCache->removeSpriteFramesFromFile(plistFile.c_str());
}
开发者ID:qjsy,项目名称:QjGit,代码行数:14,代码来源:SkillItem.cpp

示例6: loadResources

void StartLayer::loadResources()
{
    CCTextureCache * textureCache = CCTextureCache::sharedTextureCache();
    
    CCDictionary* dir = CCDictionary::createWithContentsOfFile("load.plist");
    _textures = (CCArray*)dir->objectForKey("texture");
    _textures->retain();
    for (int i = 0; i < _textures->count(); ++i)
    {
        string str = ((CCString*)_textures->objectAtIndex(i))->getCString();
        
        textureCache->addImageAsync(str.c_str(), this, callfuncO_selector(StartLayer::loadCallback));
    }
}
开发者ID:mrktj,项目名称:SlotGame,代码行数:14,代码来源:StartLayer.cpp

示例7: 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);

}
开发者ID:ccjimmy,项目名称:TweeJump4wp8,代码行数:55,代码来源:PerformanceTextureTest.cpp

示例8: removeUnusedAnimations

void ArmatureDataManager::removeUnusedAnimations(){
    if( m_pArmatureFileInfoDic ){
        CCTextureCache * tc = CCTextureCache::sharedTextureCache();
        CCSpriteFrameCache * sfc = CCSpriteFrameCache::sharedSpriteFrameCache();
        std::vector<std::string> cleanlist;
        CCDictElement* pElement = NULL;
        CCDICT_FOREACH(m_pArmatureFileInfoDic, pElement){
            const std::string file = pElement->getStrKey();
            ArmatureFileInfo * _fileInfo = (ArmatureFileInfo*)pElement->getObject();
            if (_fileInfo && _fileInfo->retainCount() == 1) {
                
                //清理 m_pAnimationDatas、m_pArmarureDatas、m_pTextureDatas 信息
                if( m_pAnimationDatas ){
                    m_pAnimationDatas->removeObjectForKey(_fileInfo->configFilePath);
                }
                
                if( m_pArmarureDatas ){
                    m_pArmarureDatas->removeObjectForKey(_fileInfo->configFilePath);
                }
                
                if( m_pTextureDatas ){
                    m_pTextureDatas->removeObjectForKey(_fileInfo->configFilePath);
                }
                
                //清理精灵帧、纹理和标记需要清理的ArmatureFile
                for (std::vector<ImageInfo>::iterator it = _fileInfo->imageInfoVector.begin();
                     it != _fileInfo->imageInfoVector.end();
                     it++){
                    const std::string & plist = it->plistPath;
                    const std::string & texture = it->imagePath;
                    sfc->removeSpriteFramesFromFile(plist.c_str());
                    tc->removeTextureForKey(texture.c_str());
                    cleanlist.push_back(file);
                }
            }
        }
        
        
        
        int size = cleanlist.size();
        for(int i = 0; i < size; i++) {
            m_pArmatureFileInfoDic->removeObjectForKey(cleanlist[i]);
        }
        cleanlist.clear();
    }
}
开发者ID:xbinglzh,项目名称:my1netFrameWork,代码行数:46,代码来源:SPArmatureDataManager.cpp

示例9: 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);
    }
}
开发者ID:saranpol,项目名称:cocos2d-x,代码行数:18,代码来源:CCSprite.cpp

示例10: transformToZombie

void SwarmGame::transformToZombie(EntitySprite& entity)
{
   EntityType toType;
   if (transformToType(entity.m_entity->type(), toType))
   {
      MobileEntity* zombie = static_cast<MobileEntity*>(EntityFactory::instance().createEntity(toType));
      if ( NULL != zombie  )
      {
         m_ZombieSwarm.addEntity(zombie);
         CCTexture2D* entityTexture = NULL;
         CCTextureCache* textureCache = CCTextureCache::sharedTextureCache();
         entityTexture = textureCache->textureForKey(xmlDataManager::instance().getEntitySprite (toType));
         int mapHeight = m_map.height() * c_blockSize;

         //create new sprite
         SpriteEntity* sprite = SpriteEntity::spriteWithEntity(zombie);
         sprite->setAnchorPoint(entity.m_sprite->getAnchorPoint());
         sprite->setScaleX(entity.m_sprite->getScaleX());
         sprite->setScaleY(entity.m_sprite->getScaleY());
         sprite->setPosition(entity.m_sprite->getPosition());

         m_mapLayer->removeChild(entity.m_sprite, true);
         entity.m_sprite = sprite; 
         entity.m_sprite->setMaxHealth( zombie->hitPoints() );
         entity.m_sprite->setIsVisible(true);
         m_mapLayer->addChild(entity.m_sprite);

         //TODO: add more properties
         m_map.removeEntity(entity.m_entity);
         m_map.placeEntity(zombie, entity.m_entity->x(), entity.m_entity->y());

         m_ZombieSwarm.removeTarget(entity.m_entity);
         m_HumanSwarm.removeEntity(entity.m_entity, true);
         //m_map->removeEntity(entity.m_entity);
         m_HumanSwarm.addTarget (zombie);

         entity.m_entity = zombie;         
      }
   }
}
开发者ID:BGCX261,项目名称:zombieswarmer-svn-to-git,代码行数:40,代码来源:SwarmGame.cpp

示例11: 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;
    }
}
开发者ID:saranpol,项目名称:cocos2d-x,代码行数:22,代码来源:CCSprite.cpp

示例12:

/*
 *  析构函数
 */
LoginLayer::~LoginLayer() {
    CCTextureCache* pTextureCache = CCTextureCache::sharedTextureCache();
    
    pTextureCache->removeTextureForKey("GAME_NAME.png");
    pTextureCache->removeTextureForKey("bg_big.png");
    pTextureCache->removeTextureForKey("pre.png");
    pTextureCache->removeTextureForKey("def.png");
    pTextureCache->removeTextureForKey("start.png");
    pTextureCache->removeTextureForKey("LG_nor.png");
    pTextureCache->removeTextureForKey("LG_sel.png");
}
开发者ID:qjsy,项目名称:QjGit,代码行数:14,代码来源:LoginLayer.cpp

示例13: 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);
}
开发者ID:fordream,项目名称:quick,代码行数:66,代码来源:CCDirector.cpp

示例14:

/*
 *  析构函数
 */
Demo::~Demo() {
    CCTextureCache* pTextureCache = CCTextureCache::sharedTextureCache();
    pTextureCache->removeTextureForKey("des.png");
    pTextureCache->removeTextureForKey("desfont.png");
}
开发者ID:qjsy,项目名称:QjGit,代码行数:8,代码来源:Demo.cpp

示例15: 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 ;
}
开发者ID:fengmm521,项目名称:qipaiproject,代码行数:65,代码来源:YJTabTitle.cpp


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