0

テクスチャパッカー(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];

だから私の問題は、(cocos2d v1.1.0-beta2b)を使用しているkobold2dを使用していて、このアニメーションを再生しようとすると、フレームの半分しか再生されないことですが、別のcocos2dプロジェクトでこの(正確な)コードを試しましたは(cocos2d v1.0.0-rc)を使用しており、チャームのように機能します。これはcocos2dのバグですか、それとも私は何か正しいことをしていませんか?

4

2 に答える 2

1

確かに、cocos2d 1.1はアニメーションの遅延の動作を変更しました。これは、意図的に、またはバグによって引き起こされた重大な変更でした(私にはわかりませんでした)。変更は非常に奇妙なので、これを数分調べた後、私はあきらめて自分のプロジェクトを1.0.1に戻しました。このアニメーションの問題は、Kobold2Dv1.0.5のダウンロードリンクを公開している理由でもあります。

たぶん、このアニメーションの変更にはある程度の用途があります。フォーラムの投稿を読みましたが、それがどのように機能するかについてさえ、私にはあまり意味がありません。あるいは、そうかもしれませんが、説明が不十分であるか、実装にバグが1つか2つあるだけです。ただし、cocos2d2.0ではこれらのアニメーションの問題は発生していません。多分それはそこで修正されたか、あるいは変更がcocos2d2.0に適用されなかったのかもしれません。

FWIW、cocos2d-iphonev1.xはもう更新されていないようです。v1.xマスターブランチへの最後の公式コミットは6か月前であり、v1.x開発ブランチへの最後のコミットは4か月前でした。船をジャンプする時が来ました。

于 2012-09-07T09:46:32.227 に答える
0

私は自分の問題を解決する方法を見つけました。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];
}

これは私にとってはうまくいきましたが、それが理想的な修正であるかどうかはわかりません。

于 2012-09-07T15:00:15.823 に答える