cocos2d-x 菜鸟实习生学习篇(七) 逐帧动画(上)

有段时间没更新博客了,这几天都比较忙,要完成boss布置的一些任务,前些天又请了四天假回校考试跟入党转正。对于实习生来说,一下子请四天假堪称胆大包天!话说入党这事真的很纠结,也不知道自己大一点时候怎么就那么傻要申请入党呢?现在有点后悔了。愤青伤不起。

这篇博客我就不参考其他高手的啦,可以看出自己这阶段确实是有点进步的!不过推荐大家看篇程序员“小说”吧。昨天无意间看到的,有一百多篇,挺喜欢的,觉得跟自己找工作时的情况很像。我想,你看了之后肯定也能从其中找到共鸣的!

http://blog.csdn.net/norains?viewmode=contents  那些年,哪些是——一个程序员的奋斗史


好,开始进入正题。

说到这个逐帧动画,额,应该是叫逐帧动画吧。对这货理解的比较容易,因为大一的时候有用半年时间自学过flash,所以用起来也还算顺。

首先从官方自带的tsetcpp说起:

在spritetest中 "Sprite offset + anchor + rot";这个例子:有如下几句:

 

//这是第一种方法,我用的也是这种
    CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
    cache->addSpriteFramesWithFile("animations/grossini.plist");
    cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
   
    CCArray* animFrames = CCArray::createWithCapacity(14);
        char str[100] = {0};
        for(int i = 0; i < 14; i++) 
        {
            sprintf(str, "grossini_dance_%02d.png",(i+1));
            CCSpriteFrame *frame = cache->spriteFrameByName(str);
            animFrames->addObject(frame);
        }

        CCAnimation* animation = CCAnimation::createWithSpriteFrames(animFrames, 0.3f);
        sprite->runAction(CCRepeatForever::create( CCAnimate::create(animation) ) );            
   
    //
    // File animation,这是第二种方法
    //
    // With 2 loops and reverse
    CCAnimationCache *cache = CCAnimationCache::sharedAnimationCache();
    cache->addAnimationsWithFile("animations/animations-2.plist");
    CCAnimation *animation2 = cache->animationByName("dance_1");

    CCAnimate* action2 = CCAnimate::create(animation2);
    m_tamara->runAction(CCSequence::create(action2, action2->reverse(), NULL));

    //
    // File animation,这是第三种方法,其实也不能这么说,它就是在第二种的基础上做了一些更基础的改动
    //
    // with 4 loops
    CCAnimation *animation3 = (CCAnimation *)animation2->copy()->autorelease();
    animation3->setLoops(4);

    CCAnimate* action3 = CCAnimate::create(animation3);
    m_kathia->runAction(action3);

好了,test就这么些,但是我必须强调的是:上面几种除了第一种,其他方法我用起来都没成功过!!!

第二种一直卡在 CCAnimation *animation2 = cache->animationByName("dance_1");这一步,为什么呢?因为 dance_1这不是图片,这是一个动画,我根本就不知道在什么时候,什么地点要做这个动画,所以,扑街。

第三种跟第二种差不多,无解。

再添加一种方法:(2013.1.10

CCArray* framesList = CCArray::create();  
  
    framesList->addObject(CCSpriteFrame::create("sprite/player1.png", CCRectMake(0, 0, 77, 134)));  
    framesList->addObject(CCSpriteFrame::create("sprite/player2.png", CCRectMake(0, 0, 66, 129)));  
    framesList->addObject(CCSpriteFrame::create("sprite/player3.png", CCRectMake(0, 0, 99, 132)));  
    framesList->addObject(CCSpriteFrame::create("sprite/player4.png", CCRectMake(0, 0, 111, 135)));  
    framesList->addObject(CCSpriteFrame::create("sprite/player5.png", CCRectMake(0, 0, 94, 132)));  
    framesList->addObject(CCSpriteFrame::create("sprite/player6.png", CCRectMake(0, 0, 64, 128)));  
    framesList->addObject(CCSpriteFrame::create("sprite/player7.png", CCRectMake(0, 0, 96, 133)));  
    framesList->addObject(CCSpriteFrame::create("sprite/player8.png", CCRectMake(0, 0, 103, 138)));  
      
    CCAnimation* animation = CCAnimation::createWithSpriteFrames(framesList, 0.2f);  
    animation->setLoops(-1);  //设置为无限循环
  
    mSprite->runAction(CCAnimate::create(animation));  


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值