void Monster_UI::runCuttleBoomAction() { auto sprite_boom = Sprite::create(); sprite->addChild(sprite_boom); auto ani = Animation::create(); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PCuttle01.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PCuttle02.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PCuttle03.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PCuttle04.png")); ani->setDelayPerUnit(0.05); ani->setRestoreOriginalFrame(false); ani->setLoops(-1); sprite_boom->runAction(Animate::create(ani)); sprite_boom->setVisible(true); sprite_boom->setPosition(sprite->getContentSize().width / 2, sprite->getContentSize().height / 2); sprite_boom->runAction(Sequence::create(DelayTime::create(0.2), CallFunc::create([=]() { sprite_boom->removeFromParentAndCleanup(true); }), nullptr)); }
void Field::InitSpriteResource() { // TODO : 하드코딩을 조져 너희를 이롭게 하리라 m_SpriteFrame = SpriteFrameCache::sharedSpriteFrameCache(); m_SpriteFrame->addSpriteFramesWithFile("block_water.plist"); m_SpriteFrame->addSpriteFramesWithFile("block_grass.plist"); m_SpriteFrame->addSpriteFramesWithFile("block_cover_water.plist"); char blockType[30]; ///< = { 0, }; 처럼 로컬 변수도 초기화 하는 습관을.. char spriteName[30]; auto waterAnimate = Animation::create(); strcpy(blockType, "block_water"); for (unsigned int i = 1; i < 12; ++i) { sprintf(spriteName, "%s%d.png", blockType, i); waterAnimate->addSpriteFrame(m_SpriteFrame->getSpriteFrameByName(spriteName)); } m_AnimationList.insert(AnimationList::value_type(FBT_WATER,waterAnimate)); auto coverwaterAnimate = Animation::create(); strcpy(blockType, "block_cover_water"); for (unsigned int i = 1; i < 12; ++i) { sprintf(spriteName, "%s%d.png", blockType, i); coverwaterAnimate->addSpriteFrame(m_SpriteFrame->getSpriteFrameByName(spriteName)); } m_AnimationList.insert(AnimationList::value_type(FBT_COVER_WATER, coverwaterAnimate)); }
bool Chicken::initWithLayer( HelloWorld * layer ) { if (initWithSpriteFrameName("chicken_001.png")) { _layer = layer; auto animation = Animation::create(); for (int i = 1; i <= 40; i++) { auto str = String::createWithFormat("chicken_%03d.png",i); auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(str->getCString()); animation->addSpriteFrame(frame); } animation->setDelayPerUnit(1.0f / 1000 * 90); setNormalAnimation(animation); animation = Animation::create(); for (int i = 1; i <= 12; i++) { auto str = String::createWithFormat("ccchick_%03d.png",i); auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(str->getCString()); animation->addSpriteFrame(frame); } animation->setDelayPerUnit(1.0f / 1000 * 40); setTrapAnimation(animation); layer->addChild(this); runAnimation(getNormalAnimation()); return true; } return false; }
void Tower_Ball::Destory() { Scene_UI*sc = (Scene_UI*)sprite->getParent(); for (vector<Tower_UI*>::iterator it = sc->tower_queue.begin(); it != sc->tower_queue.end(); ++it) { if ((*it) == this) { sc->tower_queue.erase(it); break; } } setClick(false); setTarget(0); auto x = (Scene_UI*)sprite->getParent(); x->data->pop(PublicFunc::convertToX(sprite->getPosition().x), PublicFunc::convertToY(sprite->getPosition().y)); auto ani = Animation::create(); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air01.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air02.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air03.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air04.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air05.png")); ani->setDelayPerUnit(0.1); ani->setRestoreOriginalFrame(true); ani->setLoops(1); auto an = Animate::create(ani); sprite_base->removeFromParentAndCleanup(true); effect->removeFromParentAndCleanup(true); sprite_bullet_effect->removeFromParentAndCleanup(true); sprite_upgrade->removeFromParentAndCleanup(true); sprite->runAction(Sequence::create(an, CallFunc::create([=] { sprite->removeFromParentAndCleanup(true); delete this; }), nullptr)); }
void Monster_UI::set_effect_last_damage(int lev)/*pin 持续伤害*/ { if (effect_last_damage_lev == 0) { sprite_last_damage = Sprite::create(); sprite->addChild(sprite_last_damage); auto ani1 = Animation::create(); ani1->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PPin01.png")); ani1->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PPin02.png")); ani1->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PPin03.png")); ani1->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PPin04.png")); ani1->setDelayPerUnit(0.03); ani1->setRestoreOriginalFrame(false); ani1->setLoops(-1); sprite_last_damage->runAction(Animate::create(ani1)); sprite_last_damage->setPosition(sprite->getContentSize().width / 2, 20); effect_last_damage_times = 5; sprite_last_damage->runAction(RepeatForever::create(Sequence::create(DelayTime::create(0.5), CallFunc::create([=]() { if (effect_last_damage_times >= 0) { --effect_last_damage_times; sprite_last_damage->setVisible(true); beenAttacked(effect_last_damage_lev * 1); sprite_last_damage->setPosition(sprite->getContentSize().width / 2, 20); } else { sprite_last_damage->setVisible(false); } }), nullptr))); } if (effect_last_damage_lev <= lev) { /*等级比之前的大*/ effect_last_damage_lev = lev; effect_last_damage_times = 5; sprite_last_damage->setVisible(true); } sprite_last_damage->setPosition(sprite->getContentSize().width / 2, 20); }
void Monster_UI::set_effect_pause_fish(int lev)/*fish 暂停*/ { if (effect_pause_lev_1 == 0) { sprite_effect_pause_1 = Sprite::create(); sprite->addChild(sprite_effect_pause_1); effect_pause_times_1 = 6; sprite_effect_pause_1->setPosition(sprite->getContentSize().width / 2, 50); auto ani1 = Animation::create(); ani1->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PFish-11.png")); ani1->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PFish-12.png")); ani1->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PFish-13.png")); ani1->setDelayPerUnit(0.1); ani1->setRestoreOriginalFrame(false); ani1->setLoops(-1); sprite_effect_pause_1->runAction(Animate::create(ani1)); sprite_effect_pause_1->runAction(RepeatForever::create(Sequence::create(DelayTime::create(0.12), CallFunc::create([=]() { if (effect_pause_times_1 >= 0) { --effect_pause_times_1; sprite->pause(); sprite_effect_pause_1->setVisible(true); } else { sprite_effect_pause_1->setVisible(false); sprite->resume(); } }), nullptr))); } if (effect_pause_lev_1 <= lev) { /*等级比之前的大*/ effect_pause_lev_1 = lev; effect_pause_times_1 = 6; sprite_effect_pause_1->setPosition(sprite->getContentSize().width / 2, 40); } }
void BackGroundLayer::LoadAnimationCache() { auto animationGuBlue = Animation::create(); //创建鼓面显示动画 animationGuBlue->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("blueGu.png")); animationGuBlue->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("blueGu_2.png")); animationGuBlue->setDelayPerUnit(0.2f); animationGuBlue->setRestoreOriginalFrame(true); auto animationGuRed = Animation::create(); animationGuRed->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("redGu.png")); animationGuRed->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("redGu_2.png")); animationGuRed->setDelayPerUnit(0.2f); animationGuRed->setRestoreOriginalFrame(true); AnimationCache::getInstance()->addAnimation(animationGuBlue, "guBlue_Ani"); //添加为动画缓存 AnimationCache::getInstance()->addAnimation(animationGuRed, "guRed_Ani"); }
void EnemyLayer::enemy1Blowup(Enemy* enemy1) { auto sp1 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("enemy1_down1.png"); auto sp2 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("enemy1_down2.png"); auto sp3 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("enemy1_down3.png"); auto animation = CCAnimation::create(); animation->setDelayPerUnit(0.2f); animation->addSpriteFrame(sp1); animation->addSpriteFrame(sp2); animation->addSpriteFrame(sp3); CCAnimate* animate = CCAnimate::create(animation); //CCCallFuncND可以回调一个带两个参数的方法,这个参数为消息发送者和自定义附带消息 auto removeEnemy1 = CCCallFuncND::create(this, callfuncND_selector(EnemyLayer::enemy1Remove), (void*)enemy1); auto sequence = CCSequence::create(animate, removeEnemy1, NULL); enemy1->getSprite()->runAction(sequence); }
void AtlasLoader::loadAtlas(string filename, Texture2D *texture) { string data = FileUtils::getInstance()->getStringFromFile(filename); unsigned pos;Atlas atlas; pos = data.find_first_of("\n"); string line = data.substr(0, pos); data = data.substr(pos + 1); auto sfc = SpriteFrameCache::getInstance(); while(line != ""){ sscanf(line.c_str(), "%s %d %d %f %f %f %f", atlas.name, &atlas.width, &atlas.height, &atlas.start.x, &atlas.start.y, &atlas.end.x, &atlas.end.y); atlas.start.x = 1024*atlas.start.x; atlas.start.y = 1024*atlas.start.y; atlas.end.x = 1024*atlas.end.x; atlas.end.y = 1024*atlas.end.y; pos = data.find_first_of("\n"); line = data.substr(0, pos); data = data.substr(pos + 1); // use the data to create a sprite frame // fix 1px edge bug if(atlas.name == string("land")) { atlas.start.x += 1; } Rect rect = Rect(atlas.start.x, atlas.start.y, atlas.width, atlas.height); auto frame = SpriteFrame::createWithTexture(texture, rect); //this->_spriteFrames.insert(string(atlas.name), frame); sfc->addSpriteFrame(frame, string(atlas.name)); } }
/** * 函数介绍: 将角色动作加入缓存 * 作者:wa000 * 日期:2014 */ void Player::addAnimation() { //判断是否已经加载图片资源 auto animation = AnimationCache::getInstance()->getAnimation( cocos2d::String::createWithFormat("%s-%s", _name.c_str(), _animationNames[0].c_str())->getCString()); if(animation) { return; } //加载图片资源 for(int i = 0; i < _animationNum; i++) { auto animation = Animation::create(); //设置每帧间隔时间 animation->setDelayPerUnit(0.2f); //加载每一帧 for(int j = 0; j<_animationFrameNum[i]; j++) { auto sfName = cocos2d::String::createWithFormat("%s-%s-%d.png", _name.c_str(), _animationNames[i].c_str(), j+1)->getCString(); animation->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(sfName)); } AnimationCache::getInstance()->addAnimation( animation, String::createWithFormat("%s-%s", _name.c_str(), _animationNames[i].c_str())->getCString()); } }
void Fly::deadAction() { //主机在死亡的时候会调用deadAction()方法 //先停止所有动作和定时器 stopAllActions(); unscheduleAllSelectors(); //制作主机死亡的动作 auto pAnimation = cocos2d::Animation::create(); auto pSpriteFrameCache = cocos2d::SpriteFrameCache::getInstance(); for (int i = 1; i <= FLY_BLOWUP_FRAME_COUNT; ++i) { pAnimation->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName(cocos2d::StringUtils::format("hero_blowup_%d.png", i))); } pAnimation->setDelayPerUnit(0.1f); pAnimation->setLoops(1); auto pAnimate = cocos2d::Animate::create(pAnimation); //制作主机死亡动作播放完成后的处理动作 auto pEnd = cocos2d::CallFunc::create([]() { SceneManager::getInstance()->changeScene(en_GameOverScene); CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic(GAME_OVER); }); //将死亡动作和死亡处理动作串行处理 runAction(cocos2d::Sequence::create(pAnimate, pEnd, NULL)); }
bool SmallDevil::ToDamage(int dmg){ hp -= dmg; auto blood = ParticleSystemQuad::create("bloodParticle.plist"); blood->setPosition(this->GetHitPoint()); blood->setPositionType(ParticleSystem::PositionType::RELATIVE); blood->setAutoRemoveOnFinish(true); CreatureLayer::GetInstance()->addChild(blood, 6); if(hp <= 0){ auto effect = Sprite::createWithSpriteFrameName("sdExplosion00.png"); effect->setPosition(this->getPosition()); effect->setAnchorPoint(Point::ANCHOR_MIDDLE); effect->setScale(info.option/5.0f); CreatureLayer::GetInstance()->addChild(effect, 6); auto act1 = Animation::create(); act1->setDelayPerUnit(0.03f); for(int i=0; i<4; i++){ auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(StringUtils::format("sdExplosion%02d.png", i)); act1->addSpriteFrame(frame); } auto act2 = Animate::create(act1); auto act3 = Sequence::create(act2, RemoveSelf::create(), NULL); effect->runAction(act3); return false; } return true; }
GameVersionAnimation* GameVersionAnimation::initWithType() { auto animation = Animation::create(); animation->setDelayPerUnit(0.15f); String spriteFrameName; String frameName; spriteFrameName = String("Headline_two_1-hd.png"); for (int i = 1; i <= 6; i++) { frameName = String(String::createWithFormat("Headline_two_%d-hd.png", i)->getCString()); SpriteFrame *frame; frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(frameName.getCString()); animation->addSpriteFrame(frame); } if (this->initWithSpriteFrameName(spriteFrameName.getCString())){ this->setRotation(-12); auto animateAction = RepeatForever::create(Animate::create(animation)); this->runAction(animateAction); auto rotate1 = RotateBy::create(2, 24); auto rotate2 = RotateBy::create(2, -24); auto rotation = Sequence::createWithTwoActions(rotate1, rotate2); this->runAction(rotation); } return this; }
Tower_Shit::Tower_Shit(Node*scene, Vec2 pos, int lev) { view_click = 0; count = 0; cos_upgrade = 220; this->level = lev; initTowerBase(); effect = 0; sprite = Sprite::createWithSpriteFrameName("Shit11.png"); sprite;; sprite_base = MenuItemSprite::create(Sprite::createWithSpriteFrameName("Shit-11.png"), Sprite::createWithSpriteFrameName("Shit-11.png") , [=](Ref*p) { if (view_click == 0) { ((Scene_UI*)scene)->view_click_gloal->setAllVisFalse(); view_click = new View_Click_Tower(2, this); } }); sprite_base->setPosition(pos); sprite_base;; auto ss = Menu::create(sprite_base, nullptr); ss->setPosition(0, 0); scene->addChild(ss); scene->addChild(sprite); sprite->setPosition(pos); sprite_upgrade = Sprite::createWithSpriteFrameName("showupgrade02.png"); scene->addChild(sprite_upgrade); sprite_upgrade->setPosition(sprite->getPositionX(), sprite->getPositionY() + sprite->getContentSize().height); auto ani2 = Animation::create(); ani2->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("showupgrade02.png")); ani2->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("showupgrade01.png")); ani2->setDelayPerUnit(0.1); ani2->setRestoreOriginalFrame(false); ani2->setLoops(-1); sprite_upgrade->runAction(Animate::create(ani2)); sprite_upgrade->setVisible(false); setLevel(lev); }
void Animation::addSpriteFrameWithFile(const std::string& filename) { Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(filename); Rect rect = Rect::ZERO; rect.size = texture->getContentSize(); SpriteFrame *frame = SpriteFrame::createWithTexture(texture, rect); addSpriteFrame(frame); }
void Plane::initFlyAction() { auto animation = Animation::create(); animation->setDelayPerUnit(0.1f); animation->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("hero1.png")); animation->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("hero2.png")); Animate* animate = Animate::create(animation); runAction(RepeatForever::create(animate)); m_isMoving = false; }
Animation* BirdSprite::createAnimation(const char *fmt, int count, float fps) { auto animation = Animation::create(); animation->setDelayPerUnit(1/fps); for (int i = 0; i < count; i++){ const char *filename = String::createWithFormat(fmt, i)->getCString(); auto frame = AtlasLoader::getInstance()->getSpriteFrameByName(filename); animation->addSpriteFrame(frame); } return animation; }
bool RoleEnemyBig::init() { bool bRet = false; do { CC_BREAK_IF(!Sprite::initWithSpriteFrameName("enemy3_n1.png")); // set physical body auto body = PhysicsBody::createBox(getContentSize()); body->setGroup(PHYSICAL_BODY_ENEMY_GROUP); body->setCategoryBitmask(PHYSICAL_BODY_ENEMY_BITMASK_CATEGORY); body->setContactTestBitmask(PHYSICAL_BODY_ENEMY_BITMASK_CONTACT_TEST); body->setCollisionBitmask(PHYSICAL_BODY_ENEMY_BITMASK_COLLISION); setPhysicsBody(body); // set position auto enemy1Size = getContentSize(); auto winSize = Director::getInstance()->getWinSize(); int minX = enemy1Size.width / 2; int maxX = winSize.width - enemy1Size.width / 2; int rangeX = maxX - minX; int actualX = (rand() % rangeX) + minX; setPosition(Point(actualX, winSize.height + enemy1Size.height / 2)); // run action float minDuration, maxDuration; minDuration = 2.0f; maxDuration = 4.0f; int rangeDuration = maxDuration - minDuration; int actualDuration = (rand() % rangeDuration) + minDuration; auto actionMove = MoveTo::create(actualDuration, Point(actualX, 0 - getContentSize().height / 2)); auto actionDone = RemoveSelf::create(true); auto sequence = Sequence::create(actionMove, actionDone, nullptr); runAction(sequence); auto enemy3SpriteFrame_1 = SpriteFrameCache::getInstance()->getSpriteFrameByName( "enemy3_n1.png"); auto enemy3SpriteFrame_2 = SpriteFrameCache::getInstance()->getSpriteFrameByName( "enemy3_n2.png"); auto animation = Animation::create(); animation->setDelayPerUnit(0.2f); animation->addSpriteFrame(enemy3SpriteFrame_1); animation->addSpriteFrame(enemy3SpriteFrame_2); auto animate = Animate::create(animation); runAction(RepeatForever::create(animate)); bRet = true; } while (0); return bRet; }
void Mainplan::addAnimation() { //加载飞机动画。 auto anim = Animation::create(); SpriteFrame *sf; //通过桢缓存名字动画 加入第一帧 sf =SpriteFrameCache::getInstance()->getSpriteFrameByName("hero_fly_1.png"); anim->addSpriteFrame(sf); //加入第二帧 sf =SpriteFrameCache::getInstance()->getSpriteFrameByName("hero_fly_2.png"); anim->addSpriteFrame(sf); //设置帧循环播放次数 -1代表无限循环 anim->setLoops(-1); //设置帧播放的间隔 anim->setDelayPerUnit(0.01f); //根据anim序列创建anim动画an auto an =Animate::create(anim); //让飞机运行帧动画 this->runAction(an); }
Animation* CharacterSprite::getActionAniamation(const int row) { auto animation = Animation::create(); animation->setDelayPerUnit(1.0f/4); for (int i=0; i< 3; i++) { if(i == 1) { continue; } auto frame = SpriteFrame::createWithTexture(this->getTexture(), Rect(frameSize.width*i, row*frameSize.height, frameSize.width, frameSize.height)); animation->addSpriteFrame(frame); } return animation; }
Animation* CustomTool::createAnimation(const char* animation_name, const char* pattern, int start=0, int end=10, float delay = 0.05f) { auto animation = Animation::create(); animation->setDelayPerUnit(delay); for (int j = start; j <= end; j++){ auto sfName = String::createWithFormat(pattern, j)->getCString(); auto sf = SpriteFrameCache::getInstance()->getSpriteFrameByName(sfName); animation->addSpriteFrame(sf); } AnimationCache::getInstance()->addAnimation(animation, String::create(animation_name)->getCString()); return animation; }
void Fly::startAction() { //主机在游戏开始时会先闪3次,然后循环主机动画 auto pBlink = cocos2d::Blink::create(BLINK_DURATION, BLINK_COUNT); auto pAnimation = cocos2d::Animation::create(); pAnimation->addSpriteFrame(cocos2d::SpriteFrameCache::getInstance()->getSpriteFrameByName(FLY_FRAME_1)); pAnimation->addSpriteFrame(cocos2d::SpriteFrameCache::getInstance()->getSpriteFrameByName(FLY_FRAME_2)); pAnimation->setDelayPerUnit(ANIMATE_DELAY); auto pAnimate = cocos2d::Animate::create(pAnimation); runAction(pBlink); runAction(cocos2d::RepeatForever::create(cocos2d::Sequence::create(pAnimate, NULL))); }
void Monster_fat_green::runMoveAction() { auto ani = Animation::create(); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("fat_green01.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("fat_green02.png")); ani->setDelayPerUnit(3.0 / 30.0); ani->setRestoreOriginalFrame(false); ani->setLoops(-1); auto an = Animate::create(ani); sprite->runAction(an); }
void AnimationManager::loadHeroAnimation(const char *plist) { auto cache = SpriteFrameCache::getInstance(); cache->addSpriteFramesWithFile(plist); auto animation = Animation::create(); for (int i = 1; i < 3; i++) { auto filename = StringUtils::format("mainplaneIdle%d.png", i); animation->addSpriteFrame(cache->getSpriteFrameByName(filename)); } animation->setDelayPerUnit(0.1f); animation->setLoops(-1); m_manager->addAnimation(animation, "hero-normal"); }
void GameScene::initAnimation() { // Plane animation auto planeAnimation = Animation::create(); for(int index = 1; index < 4; index++ ) { char name[50] = {0}; sprintf(name, "planeBlue%i.png", index); SpriteFrame* planeSpriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(name); planeAnimation->addSpriteFrame(planeSpriteFrame); } planeAnimation->setDelayPerUnit(0.3f / 3.0f); planeAnimation->setRestoreOriginalFrame(true); auto planeAnimate = Animate::create(planeAnimation); auto planeRepeatForever = RepeatForever::create(planeAnimate); playerSprite->runAction(planeRepeatForever); // Puff animation auto puffAnimation = Animation::create(); char name[50] = {0}; SpriteFrame* puffSpriteFrame; sprintf(name, "puffLarge.png"); puffSpriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(name); puffAnimation->addSpriteFrame(puffSpriteFrame); sprintf(name, "puffSmall.png"); puffSpriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(name); puffAnimation->addSpriteFrame(puffSpriteFrame); puffAnimation->setDelayPerUnit(0.2f / 2.0f); puffAnimation->setRestoreOriginalFrame(true); auto puffAnimate = Animate::create(puffAnimation); auto puffRepeatForever = RepeatForever::create(puffAnimate); auto puffSprite = Sprite::create(); puffSprite->runAction(puffRepeatForever); puffSprite->setPosition(Point(-playerSprite->getContentSize().width * 0.3, playerSprite->getContentSize().height * 0.7)); playerSprite->addChild(puffSprite); }
Animation* AnimationManager::getAnimationWithCacheNamed(char *format, USIZE nStart, USIZE nEnd) { auto cache = SpriteFrameCache::getInstance(); auto animation = Animation::create(); for (USIZE i = nStart; i <= nEnd; i++) { auto path = String::createWithFormat(format, i)->getCString(); auto frame = cache->getSpriteFrameByName(path); animation->addSpriteFrame(frame); } return animation; }
bool Bat::init() { Monster::init(); m_CreateTime = time(NULL); SpriteFrameCache::getInstance()->addSpriteFramesWithFile("bat.plist"); m_Sprite = Sprite::createWithSpriteFrameName("bat1.png"); m_Sprite->setAnchorPoint(Point(0.5, 0.5)); auto animation = Animation::create(); animation->setDelayPerUnit(0.15); for (int i = 0; i < 5; i++) { auto frame = SpriteFrameCache::getInstance()-> getSpriteFrameByName(StringUtils::format( "bat%d.png", i + 1)); animation->addSpriteFrame(frame); } auto animate = Animate::create(animation); m_Sprite->runAction(RepeatForever::create(animate)); this->addChild(m_Sprite); m_Width = m_Sprite->getContentSize().width; m_Height = m_Sprite->getContentSize().height; this->scheduleUpdate(); if (rand() % 2) { vy = 2; vvy = -0.1; } else { vy = -2; vvy = 0.1; } m_AttackTime = 1.6; m_AttackDelay = 0; return true; }
Animation* AnimationUtil::getAnimation( const char* filename, int frame, int fps ) { auto animation = Animation::create(); auto texture = Sprite::create( filename ); float h = texture->getContentSize().height;//这个函数是用来干啥的?这个函数是取得每一帧图片的宽高,方便之后设置动画帧 float w = texture->getContentSize().width / frame;//frame表示帧数 for ( int i = 0; i < frame; ++i ) { auto spriteFrame = SpriteFrame::create( filename, Rect( i*w, 0, w, h ) );//用前面取得的宽高设置动画帧 animation->addSpriteFrame( spriteFrame ); } animation->setDelayPerUnit( 1.0f / fps ); return animation; }
void GameStart::startGameAnimation() { auto animation = Animation::create(); int i; for (i = 1; i <= 4; i++) { auto name = String::createWithFormat("aaaa%i.png", i); auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(name->getCString()); animation->addSpriteFrame(frame); } animation->setDelayPerUnit(1 / 4.0f); animation->setRestoreOriginalFrame(true); }
void RoleEmemyBig::down() { log("RoleEmemyBig, down------------->"); auto animation = Animation::create(); animation->setDelayPerUnit(0.2f); animation->addSpriteFrame( SpriteFrameCache::getInstance()->getSpriteFrameByName( "hero_blowup_n1.png")); animation->addSpriteFrame( SpriteFrameCache::getInstance()->getSpriteFrameByName( "hero_blowup_n2.png")); animation->addSpriteFrame( SpriteFrameCache::getInstance()->getSpriteFrameByName( "hero_blowup_n3.png")); animation->addSpriteFrame( SpriteFrameCache::getInstance()->getSpriteFrameByName( "hero_blowup_n4.png")); auto animate = Animate::create(animation); auto remove = CallFunc::create( CC_CALLBACK_0(RoleEmemyBig::doRemoveSelf, this, this)); auto sequence = Sequence::create(animate, remove, nullptr); runAction(sequence); }