PlaneLayer::PlaneLayer() { Layer::init(); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); auto spriteFrameCache = cocos2d::SpriteFrameCache::sharedSpriteFrameCache(); spriteFrameCache->addSpriteFramesWithFile("shoot.plist"); auto plane = Sprite::createWithSpriteFrame(spriteFrameCache->spriteFrameByName("hero1.png")); plane->setPosition(ccp(winSize.width/2, plane->getContentSize().height/2)); addChild(plane,1,PlaneSpriteTag); Blink* blink = Blink::create(1,3); CCAnimation* animation = CCAnimation::create(); animation->setDelayPerUnit(0.1); animation->addSpriteFrame(spriteFrameCache->spriteFrameByName("hero1.png")); animation->addSpriteFrame(spriteFrameCache->spriteFrameByName("hero2.png")); CCAnimate* animate = CCAnimate::create(animation); plane->runAction(blink); plane->runAction(CCRepeatForever::create(animate)); }
void Tank::initActionSet() { auto frameCache = SpriteFrameCache::getInstance(); SpriteFrame* frame = NULL; //3.0中改用vector 而不是用Array Vector<SpriteFrame*>frameVector; /* 1.----------------加载跑动的Animation-----------------*/ for (int i = 1; i <= 8; i++) { //从缓存池中加载精灵到Vector frame = frameCache->spriteFrameByName(String::createWithFormat("blast%d.gif", i)->getCString()); frameVector.pushBack(frame); } //CCAnimate* animate = CCAnimate::create(animation); //CCRepeat* repeat = CCRepeat::create(animate, 2); //CCCallFuncN* repeatdone = CCCallFuncN::create(this, callfuncN_selector(WelcomeLayer::loadingDone)); //CCSequence* sequence = CCSequence::create(repeat, repeatdone, NULL); //用vector里面的SpriteFrame列表创建Animation 以及设置一些参数 auto run_animation = Animation::createWithSpriteFrames(frameVector, 0.05f, 1); auto animate = CCAnimate::create(run_animation); //将跑动的 Animation 取名为 running AnimationCache::getInstance()->addAnimation(run_animation, "tankboom"); ///*4---------------*/ //frameVector.clear(); //for (int i = 1; i <= 3; i++){ // frame = frameCache->spriteFrameByName(String::createWithFormat("explode-%d.png", i)->getCString()); // frameVector.pushBack(frame); //} //auto jumpUp_animation = Animation::createWithSpriteFrames(frameVector, 0.2);//不设置无限循环 //AnimationCache::getInstance()->addAnimation(jumpUp_animation, "enemyboom"); }
Bird::Bird(const std::string& filename, const std::string& c_plist, const char* c_FileNameFormat, Vec2 P0, Vec2 P1, Vec2 P2, Vec2 P3, float DelayTime, float FlyTime) { auto cache = SpriteFrameCache::getInstance(); auto frame = cache->spriteFrameByName(filename); if (frame == nullptr) { CCLOG("空=%s", filename.c_str()); cache->addSpriteFramesWithFile(c_plist); } this->initWithSpriteFrame(frame); m_P0 = P0; m_P1 = P1; m_P2 = P2; m_P3 = P3; m_DelayTime = DelayTime; m_FlyTime = FlyTime; m_FlyAnimation = FrameAnimation::create(4, c_plist, c_FileNameFormat, 0.06f); }