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


C++ CCSpriteFrameCache类代码示例

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


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

示例1: ccp

KDbool AnalogStick::init ( KDvoid )
{
	if ( !TouchableSprite::init ( ) )
	{
		return KD_FALSE;
	}

	this->setScale ( 0.5f );
		
	m_tPressedVector = ccp ( 0, 0 );
	m_nDirection = AS_NO_DIRECTION;
		
	CCSpriteFrameCache*		pCache = CCSpriteFrameCache::sharedSpriteFrameCache ( );
	pCache->addSpriteFramesWithFile ( "analog_stick.plist" );
		
	// Set the sprite display frame
	this->setDisplayFrame ( pCache->spriteFrameByName ( "analog_pad.png" ) );
		
	// Init the bar, set position and display frame
	m_pBar = CCSprite::create ( );
	m_pBar->setDisplayFrame ( pCache->spriteFrameByName ( "analog_bar.png" ) );
	this->repositionBarWithPoint ( this->getPosition ( ) );
	this->addChild ( m_pBar );
	
	// Init the nub, set position and display frame
	m_pNub = CCSprite::create ( );
	this->repositionNub ( );
	m_pNub->setDisplayFrame ( pCache->spriteFrameByName ( "analog_nub.png" ) );
	this->addChild ( m_pNub );	

	return KD_TRUE;
}
开发者ID:mcodegeeks,项目名称:OpenKODE-Framework,代码行数:32,代码来源:AnalogStick.cpp

示例2: loadUI

void BYGameScene::loadUI() {
    
    CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
    frameCache->addSpriteFramesWithFile("ui.plist", "ui.png");
    
    CCSize winSize    = CCDirector::sharedDirector()->getWinSize();    
    
    /// pause button
    CCSprite* btnNormalSprite = CCSprite::createWithSpriteFrameName("pause.png");
    CCMenuItemSprite *pauseMenuItem = CCMenuItemSprite::create(btnNormalSprite,
                                                               btnNormalSprite,
                                                               this,
                                                               menu_selector(BYGameScene::pauseButtonHandler));
    
    /// 2 labels for goals
    ccColor3B color = ccc3(220, 70, 20); /// red color
    _labelBotPlayerGoalsScored = CCLabelTTF::create("0", "Marker Felt", 40);
    _labelBotPlayerGoalsScored->setColor(color);
    CCMenuItemLabel *labelBot = CCMenuItemLabel::create(_labelBotPlayerGoalsScored, NULL, NULL);
    labelBot->setEnabled(false);
    
    _labelTopPlayerGoalsScored = CCLabelTTF::create("0", "Marker Felt", 40);
    _labelTopPlayerGoalsScored->setColor(color);
    CCMenuItemLabel *labelTop = CCMenuItemLabel::create(_labelTopPlayerGoalsScored, NULL, NULL);
    labelTop->setEnabled(false);
    
    /// CCMenu doesnt support anchorPoint as of 0x00020003 version
    CCMenu *menu = CCMenu::create(labelTop, pauseMenuItem, labelBot, NULL);
    menu->alignItemsHorizontallyWithPadding(5);
    menu->setAnchorPoint(CCPointMake(0, 0));
    menu->setPosition(CCPointMake(winSize.width - pauseMenuItem->getContentSize().width / 2,
                                  winSize.height / 2));
    menu->setRotation(90);
    this->addChild(menu);
}
开发者ID:myeyesareblind,项目名称:touchHockey,代码行数:35,代码来源:BYGameScene.cpp

示例3: displayHurt

void Mole::displayHurt()
{
		this->unscheduleAllSelectors();
		if(!isAction)
		{
			CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("mole_11.png");
			m_mole->setDisplayFrame(frame);
			CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
			frameCache->addSpriteFramesWithFile("wakuang/mole_hurt.plist");
			CCSpriteFrame* frame1 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("20543.png");
			CCSpriteFrame* frame2 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("20544.png");
			CCSpriteFrame* frame3 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("20545.png");
			CCArray* animFrames = CCArray::createWithCapacity(3);
			animFrames->addObject(frame1);
			animFrames->addObject(frame2);
			animFrames->addObject(frame3);
			CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 0.15f);
			animation->setRestoreOriginalFrame(true);
			animFrames->removeAllObjects();
			m_spade->runAction(CCAnimate::create(animation));		
			CCSpriteFrame* frame4 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("20546.png");
			CCSpriteFrame* frame5 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("20547.png");
			CCSpriteFrame* frame6 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("20548.png");
			animFrames->addObject(frame4);
			animFrames->addObject(frame5);
			animFrames->addObject(frame6);
			animation = CCAnimation::createWithSpriteFrames(animFrames, 0.15f);
			animation->setRestoreOriginalFrame(true);
			animFrames->removeAllObjects();
			CCCallFunc* call = CCCallFunc::create(this,callfunc_selector(Mole::hurtActionOver));
			m_hurt->runAction(CCSequence::create(CCAnimate::create(animation),call,NULL));
			isAction = true;
			sendEvent(type);
		}
}
开发者ID:captainwanghq,项目名称:demos,代码行数:35,代码来源:Mole.cpp

示例4: 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

示例5: AddExploisionEff

float EffectLayer::AddExploisionEff(int enemySize, CCPoint p )
{
	int NUM_FRAME = 12;
	float TIME_ANIMATION = 0.1f;

	CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
	cache->addSpriteFramesWithFile("explosion_3.plist");

	CCString* strSpriteName = CCString::create("explosion_3 (1).png");
	CCSprite* m_pSprite1 = CCSprite::createWithSpriteFrameName(strSpriteName->getCString());

	m_pSprite1->setScale(enemySize/3.0f); //////////////////////////////////////////////////////////////////////////
	
	m_pSprite1->setPosition(p);
	this->addChild(m_pSprite1);

	CCArray* animFrames = CCArray::createWithCapacity(NUM_FRAME);
	for(int i = 1; i < NUM_FRAME; i++) 
	{
		strSpriteName = CCString::createWithFormat("explosion_3 (%d).png", i);
		CCSpriteFrame* frame = cache->spriteFrameByName( strSpriteName->getCString() );
		animFrames->addObject(frame);
	}

	CCAnimation* animation = CCAnimation::createWithSpriteFrames(animFrames, TIME_ANIMATION);
	m_pSprite1->runAction(
		CCSequence::create(
			CCAnimate::create(animation), 
			CCCallFuncN::create(this, callfuncN_selector(EffectLayer::RemoveEffCallback)),
			NULL
	));

	return NUM_FRAME * TIME_ANIMATION;
}
开发者ID:doanhtdpl,项目名称:dau-truong-tri-thuc,代码行数:34,代码来源:EffectLayer.cpp

示例6: adjustScrollView

void FirstLayer::adjustScrollView(float offset)
{
	CCSize s = CCDirector::sharedDirector()->getWinSize();
	CCSpriteFrameCache *pCache =  CCSpriteFrameCache::sharedSpriteFrameCache();
	CCSprite *pPoint = (CCSprite *)this->getChildByTag(m_nCurPage);
	pPoint->setDisplayFrame(pCache->spriteFrameByName(PIC_POINT_NORMAL));
	if (offset<0)
	{
		m_nCurPage ++;
	}else
	{
		m_nCurPage --;
	}

	if (m_nCurPage <1)
	{
		m_nCurPage = 1;
	}

	if(m_nCurPage > 3)
	{
		game_process.firstPlay = false;
		CCSetBool("firstPlay", false);
		CCUserDefault::sharedUserDefault()->flush();
		SceneManager::goPlay();
	}
	else
	{
		pPoint = (CCSprite *)this->getChildByTag(m_nCurPage);
		pPoint->setDisplayFrame(pCache->spriteFrameByName(PIC_POINT_SELECTED));
		CCPoint adjustPos = ccp(-s.width * (m_nCurPage-1), 0);
		m_scroll->setContentOffset(adjustPos, true);
	}
}
开发者ID:wyklion,项目名称:pogoda,代码行数:34,代码来源:FirstLayer.cpp

示例7: addChild

void GameLayer::initPlayer()
{

	CCSpriteFrameCache* frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
		frameCache->addSpriteFramesWithFile("LuckyFlying.plist");

		CCSpriteBatchNode* pigeonFlightSheet = CCSpriteBatchNode::create("LuckyFlying.png");
		addChild(pigeonFlightSheet, 3);

		CCArray* pigeonFrames = new CCArray;
		for ( int i = 2; i <= 4; i++)
		{
			CCString* filename = CCString::createWithFormat("lucky_flying_0000%d.png", i);
			CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(filename->getCString());
			pigeonFrames->addObject(frame);
		}

		CCAnimation* flightAnim = CCAnimation::createWithSpriteFrames(pigeonFrames, 0.1);
		pigeonSprite = CCSprite::createWithSpriteFrameName("lucky_flying_00002.png");

		//pigeonSprite->setScale(0.5f);
		pigeonSprite->setPosition(ccp(SCREEN_WIDTH/2 - 500, SCREEN_WIDTH*3 + 250));

		CCAction* flightAction = CCRepeatForever::create(CCAnimate::create(flightAnim));
		pigeonSprite->runAction(flightAction);
		pigeonFlightSheet->addChild(pigeonSprite, 3);

		schedule(schedule_selector(GameLayer::tick1), 0.10f);
		schedule(schedule_selector(GameLayer::tick2), 0.03f);

}
开发者ID:aebert1,项目名称:LBird,代码行数:31,代码来源:GameLayers.cpp

示例8: init

bool FWEffectSprite::init(const char *effectName,
                       int frameCount,
                       float delay,
                       bool deleteAfterFinishing)
{
    CCString *psPlistFile = CCString::createWithFormat("%s.plist", effectName);

    CCSpriteFrameCache *psfcFrameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
    psfcFrameCache->addSpriteFramesWithFile(psPlistFile->getCString());
    
    CCString *psFrameName = CCString::createWithFormat("%s_0.png", effectName);
    const char * pccFrameName = psFrameName->getCString();
//    m_psfSpriteFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(pccFrameName);
    
    if (!CCSprite::initWithSpriteFrameName(pccFrameName))
    {
        return false;
    }
    
    CCAnimation *paAnimation = FWAnimation::create(effectName, frameCount, delay);
    CCAnimate *paAnimate = CCAnimate::create(paAnimation);
    
    if (deleteAfterFinishing)
    {
        CCCallFunc *pcfCallBack = CCCallFunc::create(this, callfunc_selector(FWEffectSprite::removeSelf));
        CCSequence *pseSeq = CCSequence::createWithTwoActions(paAnimate, pcfCallBack);
        runAction(pseSeq);
    }
    else
    {
        runAction(paAnimate);
    }
    return true;
}
开发者ID:b00yan,项目名称:Framework_cocos2dx,代码行数:34,代码来源:FWEffectSprite.cpp

示例9: setSlowDownMark

void Planet::slowDown()
{
	// 当前的逻辑禁止在一个减速期间叠加另一个减速
	if(m_bSlowDowned)
		return;

	m_bSlowDowned = true;	

	if(!m_pSlowDownMark)
	{
		setSlowDownMark(CCSprite::create());
		m_pSlowDownMark->setPosition(ccp(113,65));
		this->addChild(m_pSlowDownMark);
	}

	m_pSlowDownMark->setVisible(true);	

	CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
	cache->addSpriteFramesWithFile("SlowDownMark.plist");
	CCAnimation* animation = CCAnimation::create();
	animation->addSpriteFrame(cache->spriteFrameByName("SlowDownMark_0.png"));	
	animation->addSpriteFrame(cache->spriteFrameByName("SlowDownMark_1.png"));	
	animation->addSpriteFrame(cache->spriteFrameByName("SlowDownMark_2.png"));	
	animation->addSpriteFrame(cache->spriteFrameByName("SlowDownMark_3.png"));	
	animation->addSpriteFrame(cache->spriteFrameByName("SlowDownMark_4.png"));	
	animation->addSpriteFrame(cache->spriteFrameByName("SlowDownMark_4.png"));
	animation->setDelayPerUnit(0.2f);
	CCAnimate* animate = CCAnimate::create(animation);
	m_pSlowDownMark->runAction(CCRepeatForever::create(animate));	

	this->scheduleOnce(schedule_selector(Planet::slowDownRestore) , SLOW_DOWN_DURATION);

	if(m_pFace)
		m_pFace->cry();
}
开发者ID:daoduchai,项目名称:DogsMustDie,代码行数:35,代码来源:Planet.cpp

示例10:

void LevelGame05::musicCallback(CCObject *pSender)
{
	CCMenu *pmenu=(CCMenu *)getChildByTag(101);
	pmenu->setEnabled(true);
	CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
	 CCLayerColor *layer=( CCLayerColor *)getChildByTag(80);
	if(isMusic == true)
	{
		isMusic = false;
		/*CCDirector::sharedDirector()->end();*/
		CCMenu* pMenu = (CCMenu *)layer->getChildByTag(128);
		CCMenuItemImage *Item = (CCMenuItemImage *)pMenu->getChildByTag(127);
		Item->setNormalSpriteFrame(cache->spriteFrameByName("close-pause-music.png"));
		if(flagMusic == true)
			SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
	}
	else
	{
		isMusic =true;
		CCMenu* pMenu = (CCMenu *)layer->getChildByTag(128);
		CCMenuItemImage *Item = (CCMenuItemImage *)pMenu->getChildByTag(127);
		Item->setNormalSpriteFrame(cache->spriteFrameByName("pause-music.png"));
		if(flagMusic == true)
		{
			SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
		}
		else
		{
			SimpleAudioEngine::sharedEngine()->playBackgroundMusic("back2.mp3",true);
			flagMusic = true;
		}
	}
	//removeChildByTag(80);

}
开发者ID:rockere6,项目名称:Test,代码行数:35,代码来源:LevelGame05.cpp

示例11: addPig

void GameScene::addPig()
{
    const static int fameCount = 3;
    const static float animationDuration = 0.15f;

    CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
    cache->addSpriteFramesWithFile("pigs.plist");

    m_pPig = CCSprite::createWithSpriteFrameName("pig1");
    m_pPig->retain();
    m_pPig->setScale(0.7f);
    m_pPig->setZOrder(1);
    m_pPig->setPosition(ccp(m_VisibleOrigin.x + m_VisibleSize.width / 3, m_VisibleOrigin.y + m_VisibleSize.height / 2));
    addChild(m_pPig);

    CCArray *animFrames = CCArray::createWithCapacity(fameCount);
    for(int i = 1; i <= fameCount; i++)
    {
        CCSpriteFrame* frame = cache->spriteFrameByName(CCString::createWithFormat("pig%d", i)->getCString());
        animFrames->addObject(frame);
    }

    CCAction *action = CCRepeatForever::create(CCAnimate::create(CCAnimation::createWithSpriteFrames(animFrames, animationDuration)));
    action->setTag(kTagFlutter);
    m_pPig->runAction(action);
}
开发者ID:studio501,项目名称:fiypig,代码行数:26,代码来源:GameScene.cpp

示例12: CCRectMake

/* AnimatioinクラスhitAnimation関数定義
 * 返却型 : CCFiniteTimeAction
 * 仮引数 : int型変数count
 */
CCFiniteTimeAction* Animation::hitAnimation(int count) {
	CCDelayTime* delay = CCDelayTime::create(4);		//2秒ディレイ test用
	CCArray *animFrames = CCArray::create();			//CCArray型配列を初期化
	CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();	//キャッシュより指定したファイル名のインスタンスを取得しCCSpriteFrame型のオブジェクトframeに代入
	/* 初期値0のint型変数iが
	 * count未満の間
	 * インクリメント
	 */
	for(int i=0; i<count; i++) {
		CCString* fileName =
				CCString::createWithFormat(count == 14 ? "hit%d.png" : "defeat%d.png", i);	//countが13と同値であればhit%d.pngの、違う場合はdefeat%d.pngのファイルネームを取得しfileNameに代入
		CCSpriteFrame *frame = cache->spriteFrameByName(fileName->getCString());	//キャッシュからインスタンスを取得

		//インスタンスが取得できない場合(初回読み込み時まだインスタンスが生成されていない為)
		if(!frame) {
			CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage(fileName->getCString());			//fileNameに一致するファイルの取得
			CCRect bounds = CCRectMake(0, 0, texture->getContentSize().width, texture->getContentSize().height);	//インスタンスの座標とサイズを取得
			frame = CCSpriteFrame::createWithTexture(texture, bounds);	//テクスチャをframeに代入
		}
		animFrames->addObject(frame);	//インスタンスを配列に追加
	}
	CCAnimation* animation = CCAnimation::createWithSpriteFrames(animFrames, 0.1);	//CCSpriteFrameCacheクラスの配列を引数にCCAnimationクラスのインスタンスの生成 第二引数は1フレームの時間

	return CCAnimate::create(animation);	//CCAnimateクラスのアクションを生成して返却
}
开发者ID:usseeebaaaka,项目名称:sensuikan,代码行数:29,代码来源:Animation.cpp

示例13: createAnimWithSingleFrameN

CCAnimation* AnimationUtil::createAnimWithSingleFrameN( const char* name, float delay, unsigned int iLoops) {
    CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();

    CCArray* framesArray = CCArray::create();

    CCSpriteFrame* frame = NULL;
    int index = 1;
    do {
        frame = cache->spriteFrameByName(CCString::createWithFormat("%s%d.png", name, index++)->getCString());

        /* 不断地获取CCSpriteFrame对象,直到获取的值为NULL */
        if(frame == NULL) {
            break;
        }

        framesArray->addObject(frame);
    }while(true);

    CCAnimation* animation = CCAnimation::createWithSpriteFrames(framesArray);
    animation->setLoops(iLoops);
    animation->setRestoreOriginalFrame(true);
    animation->setDelayPerUnit(delay);

    return animation;
}
开发者ID:ruozigongzuoshi,项目名称:goddessemblem,代码行数:25,代码来源:AnimationUtil.cpp

示例14: init

bool CCActivityIndicator::init()
{
    CCSpriteFrameCache * spriteFramecache = CCSpriteFrameCache::sharedSpriteFrameCache();
    
    spriteFramecache->addSpriteFramesWithFile("ccactivityindicator.plist");
    CCSpriteBatchNode::initWithFile("ccactivityindicator.png", 1);
    
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    indicator = CCSprite::createWithSpriteFrameName("ccactivityindicator_1.gif");
    indicator->setPosition(ccp(winSize.width/2,winSize.height/2));
    addChild(indicator);
    
    animating = false;
    hidesWhenStopped = true;
    
    spriteFrames = CCArray::create();
    spriteFrames->retain();
    
    //load all sprite frames into array
    for (int i=1; i<=kActivityIndicatorFramesCount; i++) {
        CCSpriteFrame * frame = spriteFramecache->spriteFrameByName(CCString::createWithFormat("ccactivityindicator_%d.gif",i)->getCString());
        spriteFrames->addObject(frame);
    }
    
    return true;
}
开发者ID:JLimqueco,项目名称:cocos2d-x-extensions,代码行数:26,代码来源:CCActivityIndicator.cpp

示例15: init

bool BulletPool::init()
{
	bool bRet = false;
    
    do {
		bullets = CCArray::createWithCapacity(MAX_SIZE);
		bullets->retain();
		CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
		cache->addSpriteFramesWithFile("bullet.plist");

		bspritesheet =  CCSpriteBatchNode::create("bullet.png");

		for (int i = 0; i < MAX_SIZE; i ++)
		{
			Bullet *bullet = Bullet::create("W1.png", bspritesheet, NULL);
			bullet->setVisible(false);
			bullet->setRotation(90.0f);
			bullets->addObject(bullet);
		}

		next = 0;

		bRet = true;
	} while (0);
	
	return bRet;

}
开发者ID:Ken93,项目名称:Simple2dShooter,代码行数:28,代码来源:BulletPool.cpp


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