【问题标题】:Kobold2d animation problemsKobold2d 动画问题
【发布时间】:2012-09-06 17:11:15
【问题描述】:

我正在尝试使用我使用纹理打包器 (footballAnim-hd.pvr.ccz) 和 (footballAnim.pv-hd.plist) 创建的这些文件播放动画,但我遇到了问题。这是我的代码:

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"footballAnim.pv.plist"];

    CCSprite *football = [CCSprite spriteWithSpriteFrameName:@"Football59-hd.png"];
    football.position = ccp(100, 100);

    CCSprite *football2 = [CCSprite spriteWithSpriteFrameName:@"Football59-hd.png"];
    football2.position = ccp(120, 100);

    //This is the animation
    id anim = [CCAnimate actionWithSpriteSequence:@"Football%d-hd.png"
                                                  numFrames:59
                                                      delay:0.01
                                       restoreOriginalFrame:NO];
    //This is the animation
    id anim2 = [CCAnimate actionWithSpriteSequence:@"Football%d-hd.png"
                                        numFrames:59
                                            delay:0.01
                             restoreOriginalFrame:NO];

    //This is the action
    id repeat = [CCRepeatForever actionWithAction:anim];

    //This is the action
    id repeat2 = [CCRepeatForever actionWithAction:anim2];

     CCSpriteBatchNode *batchNode=[CCSpriteBatchNode batchNodeWithFile:@"footballAnim.pvr.ccz"];
    [self addChild:batchNode];
    [batchNode addChild:football];
    [batchNode addChild:football2];

    [football runAction:repeat];
    [football2 runAction:repeat2];

所以我的问题是我使用的是 kobold2d,它正在使用 (cocos2d v1.1.0-beta2b),当我尝试播放这个动画时,它只播放了一半的帧,但后来我在另一个中尝试了这个 (EXACT) 代码正在使用的 cocos2d 项目(cocos2d v1.0.0-rc),它就像一个魅力。这是 cocos2d 的错误还是我做的不对?

【问题讨论】:

    标签: cocos2d-iphone kobold2d


    【解决方案1】:

    确实 cocos2d 1.1 改变了动画延迟的工作方式,这是一个有意或由错误引起的重大改变(我真的无法判断)。这个变化太奇怪了,在研究了几分钟后,我放弃了,把我自己的项目恢复到 1.0.1。这个动画问题也是我保留 Kobold2D v1.0.5 下载链接的原因。

    也许这个动画更改有一些用处,我阅读了论坛帖子,但即使它应该如何工作对我来说也没有真正意义。或者它确实有,只是解释得不好,或者实现只是有一个或两个错误。我在 cocos2d 2.0 中没有这些动画问题。也许它在那里被修复了,或者这个变化从未应用于 cocos2d 2.0。

    FWIW,cocos2d-iphone v1.x 好像没有更新了。 v1.x master 分支的最后一次正式提交是 6 个月前,v1.x 开发分支的最后一次提交是 4 个月前。是时候跳船了。

    【讨论】:

      【解决方案2】:

      我想出了如何解决我的问题。 cocos2d论坛上有人建议更改CCActionInterval.m中的更新方法(从此)

      -(void) update: (ccTime) t
      {
          NSArray *frames = [animation_ frames];
          NSUInteger numberOfFrames = [frames count];
          CCSpriteFrame *frameToDisplay = nil;
      
          for( NSUInteger i=nextFrame_; i < numberOfFrames; i++ ) {
              NSNumber *splitTime = [splitTimes_ objectAtIndex:i];
      
              if( [splitTime floatValue] <= t ) {
                  CCAnimationFrame *frame = [frames objectAtIndex:i];
                  frameToDisplay = [frame spriteFrame];
                  [(CCSprite*)target_ setDisplayFrame: frameToDisplay];
      
                  NSDictionary *dict = [frame userInfo];
                  if( dict )
                      [[NSNotificationCenter defaultCenter] postNotificationName:CCAnimationFrameDisplayedNotification object:target_ userInfo:dict];
      
                  nextFrame_ = i+1;
      
                  break;
              }
          }
      }
      

      到这里

      -(void) update: (ccTime) t
      {
          NSArray *frames = [animation_ frames];
          NSUInteger numberOfFrames = [frames count];
      
          NSUInteger idx = t * numberOfFrames;
      
          if( idx >= numberOfFrames )
              idx = numberOfFrames -1;
      
          CCAnimationFrame *frame = [frames objectAtIndex:idx];
          CCSpriteFrame *frameToDisplay = [frame spriteFrame];
          [(CCSprite*)target_ setDisplayFrame: frameToDisplay];
      
          NSDictionary *dict = [frame userInfo];
          if( dict )
              [[NSNotificationCenter defaultCenter] postNotificationName:CCAnimationFrameDisplayedNotification object:target_ userInfo:dict];
      }
      

      这对我有用,但我不知道这是否是理想的解决方案。

      【讨论】:

        猜你喜欢
        • 2011-08-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-10-28
        • 2012-10-08
        • 2011-03-28
        • 2016-02-09
        相关资源
        最近更新 更多