Пример #1
0
CCAction* ActionManager::getRoleAction(ROLE_STATE currentState,ROLE_STATE nextState)
{
	CCAction * action = NULL;
	CCArray* upArray = CCArray::create(); 
	upArray->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("up_1"));
	upArray->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("up_2"));
	upArray->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("up_3"));
	upArray->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("up_4"));
	CCArray* downArray = CCArray::create(); 
	downArray->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("down_1"));
	downArray->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("down_2"));
	downArray->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("down_3"));
	downArray->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("down_4"));
	CCAnimation *animation1 = NULL,*animation2 = NULL;
	CCAnimate *animate = NULL;
	switch(nextState)
	{
	case ROLE_SECOND_UP:case ROLE_FIRST_UP:
		action = CCAnimate::create(CCAnimation::createWithSpriteFrames(upArray,  1/60.0));
		break;
	case ROLE_SECOND_DOWN:case ROLE_FIRST_DOWN:
		upArray->reverseObjects();
		action = CCSequence::create(	CCAnimate::create(CCAnimation::createWithSpriteFrames(upArray, 1/60.0)),
										CCAnimate::create(CCAnimation::createWithSpriteFrames(downArray,  1/60.0)),NULL);
		break;
	case ROLE_RUN:
		if(currentState == ROLE_FIRST_DOWN || currentState == ROLE_SECOND_DOWN)
		{
			downArray->reverseObjects();
			action = CCAnimate::create(CCAnimation::createWithSpriteFrames(downArray, 2/60.0));
		}
		break;
	}
	return action;
}
Пример #2
0
void BSMakeCachedAnimation(const char* pNameFormat, unsigned int pStartNum, unsigned int pEndNum, float pInterval, const char* pCacheName, bool pIsLoop, bool isReverse /* = false */) {
    CCArray* array = CCArray::create();
    for (unsigned int i = pStartNum; i <= pEndNum; i++) {
        char name[256] = {0};
        sprintf(name, pNameFormat, i);
        array->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name));
    }
    
    if (isReverse) {
        array->reverseObjects();
    }
    
    if (pIsLoop) {
        for (unsigned int i = pEndNum; i >= pStartNum; i--) {
            char name[256] = {0};
            sprintf(name, pNameFormat, i);
            array->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name));
        }
    }
    CCAnimation* animation = CCAnimation::createWithSpriteFrames(array, pInterval);
    CCAnimationCache::sharedAnimationCache()->addAnimation(animation, pCacheName);
}
Пример #3
0
bool CMainSelect::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    this->setTouchEnabled(true);
   
    // 创建背景
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    CCSprite* backgroud = CCSprite::create("mainsel/bg.png");
    backgroud->setPosition( ccp(size.width/2, size.height/2) );
    this->addChild(backgroud);
    
    // 按钮
    CCMenuItemImage *pLack = CCMenuItemImage::create("mainsel/lackNor.png",
                                                     "mainsel/lackSel.png",
                                                      this,
                                                      menu_selector(CMainSelect::lakeCallback) );
    
    CCMenuItemImage *pForest = CCMenuItemImage::create("mainsel/forestNor.png",
                                                       "mainsel/forestSel.png",
                                                       this,
                                                       menu_selector(CMainSelect::forestCallback) );
    
    CCMenuItemImage *pDesert = CCMenuItemImage::create("mainsel/desertNor.png",
                                                       "mainsel/desertSel.png",
                                                        this,
                                                        menu_selector(CMainSelect::desertCallback) );
    
    CCMenuItemImage *pPrairie = CCMenuItemImage::create("mainsel/prairieNor.png",
                                                        "mainsel/prairieSel.png",
                                                        this,
                                                        menu_selector(CMainSelect::prairieCallback) );
    
    pLack->setPosition(    ccp(171, 437) );
    pForest->setPosition(  ccp(539, 401) );
    pDesert->setPosition(  ccp(864, 411) );
    pPrairie->setPosition( ccp(392, 208) );
    
   
    CCMenu* pMenu = CCMenu::create(pLack, pForest, pDesert, pPrairie, NULL);
    pMenu->setPosition( CCPointZero );
    this->addChild(pMenu, 1);
    
    // 创建sprite sheet
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("mainsel/jingyu.plist");
    CCSpriteBatchNode *spriteSheet = CCSpriteBatchNode::create("mainsel/jingyu.png");
    this->addChild(spriteSheet);
    
    // 创建对象
    CCSprite *sprite = CCSprite::createWithSpriteFrameName("jingyu01.png");        
    sprite->setPosition(ccp(920,220));
    spriteSheet->addChild(sprite, 0);
          
    CCArray *arrShang = CCArray::create(); // 动画帧数组
    for(int i=1; i<=8; ++i)
    {     
        CCString *name = CCString::createWithFormat("jingyu%02d.png", i);
        arrShang->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString()));
    }
    
    CCArray *arrPeng = CCArray::create(); // 动画帧数组
    for(int i=9; i<=11; ++i)
    {
        CCString *name = CCString::createWithFormat("jingyu%02d.png", i);
        arrPeng->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString()));
    }
    CCArray *arrPengRev = CCArray::createWithArray(arrPeng);
    arrPengRev->reverseObjects();
    arrPeng->addObjectsFromArray(arrPengRev);
    
    CCFiniteTimeAction *delay = CCDelayTime::create(1);

    CCAnimate* anShang = CCAnimate::create(CCAnimation::createWithSpriteFrames(arrShang, 0.25));
    CCAnimate* anPeng  = CCAnimate::create(CCAnimation::createWithSpriteFrames(arrPeng, 0.15));
    sprite->runAction(CCRepeatForever::create((CCActionInterval*)CCSequence::create(anShang, delay, anPeng,anPeng, anPeng, anPeng, anPeng, anShang->reverse(),delay,delay,delay,NULL)));
    return true;
}