本文整理汇总了C++中CCAnimation类的典型用法代码示例。如果您正苦于以下问题:C++ CCAnimation类的具体用法?C++ CCAnimation怎么用?C++ CCAnimation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CCAnimation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CC_BREAK_IF
bool Snake::init()
{
bool bRet = false;
do
{
CC_BREAK_IF(!CCSprite::initWithFile("snake1.png"));
pLife->setPosition(ccp(pLife->getContentSize().width / 2,this->getContentSize().height + pLife->getContentSize().height));
CCAnimation* animation =CCAnimation::create();
//char *spriteImg[] = {"snake1.png","snake2.png","snake3.png","snake4.png","snake5.png","snake6.png","snake7.png"};
char str[20];
for(int i=0;i<7;i++)
{
sprintf(str,"snake%d.png",i + 1);
animation->addSpriteFrameWithFileName(str);
}
animation->setDelayPerUnit(0.1f);
animation->setRestoreOriginalFrame(true);
myAction = CCRepeatForever::create(CCAnimate::create(animation));
myAction->retain();
CCSize size = CCDirector::sharedDirector()->getWinSize();
this->setPosition(ccp(size.width, 12));
produceLoc = ccp(size.width, 12);
bRet = true;
} while (0);
return bRet;
}
示例2: 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;
}
示例3: schedule
void LoadScene::onEnter()
{
CScene::onEnter();
CSVFile* file = (CSVFile*)FileUtils::sharedFileUtils()->loadCSVFile(CSV_ROOT("preloadRes.csv"));
schedule(schedule_selector(LoadScene::loadResource));
//进度条
mProgress = (CProgressBar*)m_ui->findWidgetById("progress");
mProgress->setMaxValue(100);
//僵尸跳
CCAnimation *pZombieEffect = AnimationManager::sharedAction()->getAnimation("9049");
pZombieEffect->setDelayPerUnit(0.05f);
CCAnimate* pAnimate = CCAnimate::create(pZombieEffect);
CCSprite* pZombieSprite = CCSprite::create();
pZombieSprite->setScale(0.9f);
pZombieSprite->setAnchorPoint(ccp(0.5f, 0.0f));
pZombieSprite->setPositionY(mProgress->getPositionY()+5);
m_ui->addChild(pZombieSprite);
pZombieSprite->runAction(CCRepeatForever::create(pAnimate));
m_pZombieSprite = pZombieSprite;
CCSprite* tBackround = (CCSprite*)m_ui->findWidgetById("bg");
tBackround->initWithFile("warScene/LoadImage/1.png"); //容错性处理
}
示例4: va_start
void Trooper::animate(const char* animationName, ...){
va_list params;
va_start(params, animationName);
const char* nextName = animationName;
if (m_current_sprite != NULL && m_animate_action != NULL){
m_current_sprite->stopAction(m_animate_action);
m_animate_action = NULL;
}
CCArray* animations = CCArray::array();
while (nextName){
CCAnimation* anim = TFAnimationCache::sharedAnimationCache()->animationByName(nextName);
if (m_current_sprite == NULL){
m_current_sprite = CCSprite::spriteWithSpriteFrame(anim->getFrames()->getObjectAtIndex(0));
this->addChild(m_current_sprite);
}
CCCallFuncO* notifyAction = CCCallFuncO::actionWithTarget(this, callfuncO_selector(Trooper::onAnimationStart), new CCString(nextName));
animations->addObject(notifyAction);
nextName = va_arg(params, const char*);
if (nextName == NULL){
CCCallFuncO* animAction = CCCallFuncO::actionWithTarget(this, callfuncO_selector(Trooper::animateForever), anim);
animations->addObject(animAction);
animAction->retain();
} else {
animations->addObject(CCAnimate::actionWithAnimation(anim));
}
notifyAction->retain();
}
m_current_sprite->runAction(CCSequence::actionsWithArray(animations));
va_end(params);
animations->retain();
}
示例5: CC_BREAK_IF
bool PlaneLayer::init()
{
bool bRet = false;
do
{
CC_BREAK_IF(!CCLayer::init());
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
//CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ui/shoot.plist");
CCSprite* plane = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("hero1.png"));
plane->setPosition(ccp(winSize.width/2,plane->getContentSize().height/2));
this->addChild(plane,0,AIRPLANE);
CCBlink* blink = CCBlink::create(1,3);
CCAnimation* animation = CCAnimation::create();
animation->setDelayPerUnit(0.1f);
animation->addSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("hero1.png"));
animation->addSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("hero2.png"));
CCAnimate* animate = CCAnimate::create(animation);
plane->runAction(blink);
plane->runAction(CCRepeatForever::create(animate));
bRet = true;
} while (0);
return bRet;
}
示例6: STATIC_DATA_INT
//-----------------------------------------------------------------------------
//todo 预载入资源,实现StartScene后将其删除
void CGameScene::preloadResources()
{
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("fishingjoy_resource.plist");
//以下代码创建了两个不同的动画帧序列,使用时获取动画可以这么做:CCAnimation* animation = CCAnimationCache::sharedAnimationCache()->animationByName(const char* name);
int frameCount = STATIC_DATA_INT("fish_frame_count");
for (int type = k_Fish_Type_Red; type < k_Fish_Type_Count; type++)
{
//以下代码会创建animation失败
// CCAnimation* fishAnimation = CCAnimation::create();
// for (int i = 0; i < frameCount; i++)
// {
// fishAnimation->addSpriteFrameWithFileName(
// CCString::createWithFormat(STATIC_DATA_STRING("fish_frame_name_format"), type, i)->getCString());
// }
CCArray* spriteFramesArray = CCArray::createWithCapacity(frameCount);
for (int i = 0; i < frameCount; i++)
{
CCString* fileName = CCString::createWithFormat(STATIC_DATA_STRING("fish_frame_name_format"), type, i);
CCSpriteFrame* spriteFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(fileName->getCString());
spriteFramesArray->addObject(spriteFrame);
}
CCAnimation* fishAnimation = CCAnimation::createWithSpriteFrames(spriteFramesArray);
fishAnimation->setDelayPerUnit(STATIC_DATA_FLOAT("fish_frame_delay"));
CCString* animationName = CCString::createWithFormat(STATIC_DATA_STRING("fish_animation"),type);
CCAnimationCache::sharedAnimationCache()->addAnimation(fishAnimation, animationName->getCString());
}
}
示例7: sprintf
}
CCAction* HelloWorld::createAction(int begin,int end,char* cacheActionName,CCPoint point){
CCAnimationCache *animCache = CCAnimationCache::sharedAnimationCache();
CCArray *array = CCArray::createWithCapacity(end-begin);
char name[20];
for(int i = begin ;i<end;i++){
sprintf(name,"A1_%d.png",i);
CCSpriteFrame* frame =cache->spriteFrameByName(name);
array->addObject(frame);
}
CCAnimation *plistAnimation = CCAnimation::createWithSpriteFrames(array,0.2f);
CCAnimationCache::sharedAnimationCache()->addAnimation(plistAnimation, cacheActionName);
array->removeAllObjects();
CCAnimation *animation = animCache->animationByName(cacheActionName);
animation->setRestoreOriginalFrame(true);
CCAnimate *ani=CCAnimate::create(animation);
CCActionInterval* plistSeq=(CCActionInterval*)(CCSequence::create(ani,
CCFlipX::create(point.x>0? true:false),
ani->copy()->autorelease(),
NULL
));
示例8: AttackAnimation
//攻击动画
void Monster::AttackAnimation(const char *name_each,const unsigned int num,bool run_directon)
{
//正在走动、攻击、受伤或已死亡,就返回
if(IsRunning||IsAttack||IsHurt||Isdead)
return;
CCAnimation* animation = CCAnimation::create();
for( int i=1;i<=num;i++)
{
char szName[100] = {0};
sprintf(szName,"%s%d.png",name_each,i);
animation->addSpriteFrameWithFileName(szName); //加载动画的帧
}
animation->setDelayPerUnit(0.1f);
animation->setRestoreOriginalFrame(true);
animation->setLoops(1); //动画循环1次
//将动画包装成一个动作
CCAnimate* act=CCAnimate::create(animation);
//创建回调动作,攻击结束后调用AttackEnd()
CCCallFunc* callFunc=CCCallFunc::create(this,callfunc_selector(Monster::AttackEnd));
//创建连续动作
CCActionInterval* attackact=CCSequence::create(act,callFunc,NULL);
m_MonsterSprite->runAction(attackact);
IsAttack=true;
}
示例9: SetAnimation
//怪物走动的动画
void Monster::SetAnimation(const char *name_each,unsigned int num,bool run_directon)
{
//设置方向
if(MonsterDirecton!=run_directon)
{ MonsterDirecton=run_directon;
m_MonsterSprite->setFlipX(run_directon);
}
//正在走动、攻击、受伤或已死亡,就返回
if(IsRunning||IsAttack||IsHurt||Isdead)
return;
//设置动画
CCAnimation* animation = CCAnimation::create();
for( int i=1;i<=num;i++)
{
char szName[100] = {0};
sprintf(szName,"%s%d.png",name_each,i);
animation->addSpriteFrameWithFileName(szName); //加载动画的帧
}
animation->setDelayPerUnit(0.1f);//每两张图片的时间间隔
animation->setRestoreOriginalFrame(true);
animation->setLoops(-1); //动画循环
//将动画包装成一个动作
CCAnimate* act=CCAnimate::create(animation);
m_MonsterSprite->runAction(act);
IsRunning=true;
}
示例10: 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();
}
示例11: botisGangLied
void ASBot::botisGangLied(){
CCSprite* ani = CCSprite::createWithSpriteFrameName("Miku_GL_0.png");
ani->setRotation(-90);
ani->setScale(2);
ani->setPosition(ccp(size.width*5/40,size.height*80.3/90+winDif*2*alpha*alpha));
player1->addChild(ani,100);
CCAnimation* pAnimation = CCAnimation::create();
for (int i = 0 ; i < 16; i++) {
string texName = "Miku_GL_" + int2string(i) + ".png";
CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(texName.c_str());
pAnimation->addSpriteFrame(frame);
}
pAnimation->setDelayPerUnit(0.1);
pAnimation->setRestoreOriginalFrame(true);
pAnimation->setLoops(1);
CCAnimate* pAnimate = CCAnimate::create(pAnimation);
CCActionInterval* attack = CCMoveBy::create(1.8, ccp(size.width*30/40,0));
CCActionInterval* effect = CCSpawn::create(pAnimate,attack,NULL);
CCCallFunc* remove = CCCallFuncN::create(player1, callfuncN_selector(ASGame::removeSprite));
CCCallFunc* add = CCCallFuncN::create(this, callfuncN_selector(ASBot::botMinusHpByGangLie));
CCSequence* seq = CCSequence::create(effect,remove,add,NULL);
ani->runAction(seq);
}
示例12: startProcess
void UICenterItem::startProcess()
{
valid = false;
// 创建一个动画 自身播放时间到后将valid 设置为true
CCAnimation* animation = CCAnimation::create();
std::string frameNames[] = {
std::string("skill_p_00000.png"),
std::string("skill_p_00001.png"),
std::string("skill_p_00002.png"),
std::string("skill_p_00003.png"),
std::string("skill_p_00004.png"),
std::string("skill_p_00005.png"),
};
for (int i = 0; i < 3; i++)
{
CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage(frameNames[i].c_str());
CCSpriteFrame *frame = CCSpriteFrame::frameWithTexture(texture,CCRectMake(0,0,texture->getContentSize().width,texture->getContentSize().height));
animation->addSpriteFrame(frame);
}
CCSprite * temp = CCSprite::create();
this->getParent()->addChild(temp);
temp->setPosition(this->getPosition());
animation->setDelayPerUnit(1.5f / 2);
animation->setRestoreOriginalFrame(true);
temp->runAction(CCSequence::create(CCAnimate::create(animation),
CCCallFuncND::create(this, callfuncND_selector(UICenterItem::actionEnd_setValid), (void*)temp),NULL));
}
示例13: ccp
void CSmeltArmor::initFire()
{
//获取参考位置
CCNode* pNode = (CCNode*)m_ui->findWidgetById("fire_circle");
CCPoint pPos = ccp(pNode->getPositionX()+15, pNode->getPositionY()+75);
if(m_pFire1 == nullptr)
{
CCAnimation* pAnimation = AnimationManager::sharedAction()->getAnimation("9010");
pAnimation->setDelayPerUnit(0.15f);
m_pFire1 = CCSprite::create("skill/9010.png");
m_pFire1->setPosition(pPos);
m_pFire1->runAction(CCRepeatForever::create(CCAnimate::create(pAnimation)));
m_pFire1->setVisible(false);
m_pFire1->setScale(1.6f);
pNode->getParent()->addChild(m_pFire1, pNode->getZOrder());
}
if(m_pFire2 == nullptr)
{
CCAnimation* pAnimation = AnimationManager::sharedAction()->getAnimation("9011");
pAnimation->setDelayPerUnit(0.15f);
m_pFire2 = CCSprite::create("skill/9011.png");
m_pFire2->setPosition(pPos);
m_pFire2->runAction(CCRepeatForever::create(CCAnimate::create(pAnimation)));
m_pFire2->setVisible(false);
m_pFire2->setScale(1.5f);
pNode->getParent()->addChild(m_pFire2, pNode->getZOrder());
}
}
示例14: deleteExploreShit
float Snake::moveBack()
{
//CCSprite::initWithFile("snakeBack1.png");
//pLife->setRotationY(180);
deleteExploreShit();
this->stopAllActions();
CCAnimation* animation =CCAnimation::create();
char str[20];
for(int i=0;i<3;i++)
{
sprintf(str,"snakeBack%d.png",i + 1);
animation->addSpriteFrameWithFileName(str);
}
animation->setDelayPerUnit(0.2f);
animation->setRestoreOriginalFrame(true);
myAction = CCRepeatForever::create(CCAnimate::create(animation));
this->runAction(myAction);
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCActionInterval *move = CCMoveTo::create(moveTime / 2,ccp(size.width, 12));
moveTo = CCSequence::create(move/*,CCCallFuncN::create(this,callfuncN_selector(GameLayer::deleteAnimal))*/,NULL);
this->runAction(moveTo);
hasMoveBack = true;
return moveTime / 2;
}
示例15: addChild
void ASFightLayer::SheldonSecondPeriodCritical(){
//1.击中特效
CCSprite* hitEffect = CCSprite::createWithSpriteFrameName("Sheldon_C2_0.png");
hitEffect->setScale(2);
hitEffect->setPosition(ccp(size.width*2/3,winSize.height/2));
addChild(hitEffect,4);
CCAnimation* pAnimation = CCAnimation::create();
for (int i = 0 ; i < 24; i++) {
string texName = "Sheldon_C2_" + int2string(i) + ".png";
CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(texName.c_str());
pAnimation->addSpriteFrame(frame);
}
pAnimation->setDelayPerUnit(0.1);
pAnimation->setRestoreOriginalFrame(true);
pAnimation->setLoops(1);
CCAnimate* pAnimate = CCAnimate::create(pAnimation);
CCCallFunc* remove = CCCallFuncN::create(this, callfuncN_selector(ASFightLayer::removeThis));
CCSequence* effect1 = CCSequence::create(pAnimate,remove,NULL);
CCDelayTime* delay = CCDelayTime::create(1.5);
CCCallFunc* hit = CCCallFuncN::create(this, callfuncN_selector(ASFightLayer::SheldonSecondHitEnemy));
CCSequence* effect2= CCSequence::create(delay,hit,NULL);
CCActionInterval* effect3 = CCSpawn::create(effect1,effect2,NULL);
hitEffect->runAction(effect3);
}