cococos 2 d-x 3.0フレーム再生(フレームアニメーションループ再生)


nbオリジナル、転載を歓迎して、転載して明らかな所で明記してください! Thx~
原文住所:http://blog.csdn.net/nilreb_nb/article/details/17161339
以前は2.0で開発されていましたが、2.0でフレーム再生するにはCCMutableArrayというコンテナ配列が必要でしたが、3.0にはもうこの配列がないので、testCppのAnimationソースコードを見て、3.0でフレーム再生をどのように実現するかを説明しました.
    
直接コードをつけました
(1)手動でフレーム放送を実現する
auto animation = Animation::create(); 
	char str[64] = {0};
	for(int i=0;i<18;i++){//    18   ,  test1   
		sprintf(str,"test1/%d.png",i+1);
		animation->addSpriteFrameWithFileName(str);
	}
	animation->setDelayPerUnit(3.0f / 18.0f);//        3 ,  18   
        animation->setRestoreOriginalFrame(true);
	auto action = Animate::create(animation);
	auto run1 = CCSprite::create();//    sprite     
	run1->setPosition(ccp(contsize.width/2,contsize.height/10*6));
	this->addChild(run1,12);
        run1->runAction(Sequence::create(action, NULL));
auto animation = Animation::create();        Animation* animation = Animation::create();

 この2つの定義は1つの意味で、私はautoを使うことに慣れて、便利で手間が省けます.
またループ再生を実現したいなら、簡単で、CCRepeat(限定)とCCRepeatForever(無限ループ)で
auto Call = CCCallFuncND::create(this,callfuncND_selector(CombatSystemLayer::repeatFunc),pdata);
	auto run = CCSprite::create();
	this->addChild(run,1);
	auto seq3 = Sequence::create(Call,DelayTime::create(8.0f),NULL);//         
	//CCRepeatForever* repeat=CCRepeatForever::create(seq1);//    
	auto rep2 = CCRepeat::create(seq3,5);//   seq3    5 
	auto seq4 = Sequence::create(DelayTime::create(3.5f), rep2, NULL);

(2)ファイル実装フレーム再生(これはtestCppのソースコード)
AnimationCache *cache = AnimationCache::getInstance();
    cache->addAnimationsWithFile("animations/animations-2.plist");//  plist  
    Animation *animation2 = cache->animationByName("dance_1");

    Animate* action2 = Animate::create(animation2);
    _tamara->runAction(Sequence::create(action2, action2->reverse(), NULL));