首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Kobold2d动画问题

Kobold2d动画问题
EN

Stack Overflow用户
提问于 2012-09-07 01:11:15
回答 2查看 183关注 0票数 0

我正在尝试使用这些文件播放动画,这些文件是我用texture packer ( have -hd.pvr.ccz)和(have Anim.pv-hd.plist)创建的,但我遇到了一个问题。下面是我的代码:

代码语言:javascript
复制
[[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),当我试图播放这个动画时,它只播放了一半的帧,但是后来我在另一个使用(cocos2d v1.0.0-rc)的cocos2d项目中尝试了这个(精确的)代码,它工作得很棒。这是cocos2d中的一个bug,还是我做错了什么?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-09-07 23:00:16

我想出了怎么解决我的问题。cocos2d论坛上有人建议更改CCActionInterval.m中的更新方法(如下所示)

代码语言:javascript
复制
-(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;
        }
    }
}

到这个

代码语言:javascript
复制
-(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];
}

这对我来说很有效,但我不知道这是否是理想的解决方案。

票数 0
EN

Stack Overflow用户

发布于 2012-09-07 17:46:32

事实上,cocos2d 1.1改变了动画延迟的工作方式,这是一个突破性的变化,无论是故意的还是由错误引起的(我真的说不清)。这个变化太奇怪了,在研究了几分钟后,我放弃了,并将我自己的项目恢复到了1.0.1。这个动画问题也是我保留Kobold2D v1.0.5下载链接的原因。

也许这个动画改变有一些用处,我读了论坛的帖子,但即使它是如何工作的,对我来说也没有真正的意义。或者它确实是这样的,只是解释得很糟糕,或者实现只是有一两个bug。不过,我在cocos2d 2.0中还没有遇到这些动画问题。也许它在那里被修复了,或者可能这个更改从未应用到cocos2d 2.0。

FWIW,cocos2d-iphone v1.x似乎不再更新。最后一次正式提交到v1.x主分支是6个月前,最后一次提交到v1.x开发分支是4个月前。是时候跳船了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12305100

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档