0

アーティストからスプライトシートPNG​​が送られてきました。スプライトシートの内側には、それぞれ32x32の4つのスプライトがあり、アニメーションを作成します。アニメーションを実行するCCSpriteを画面に表示できるようにしたいと思います。いろいろ試してみましたが、実はスプライトシートの概念がよくわかりません。私は、プロパティリストなどを必要とするウェブの周りにあらゆる種類のものを見ています。アーティストから得たのは単純なPNGだけです。助けてください?

4

2 に答える 2

1

私もこの問題を抱えていました。これは私が思いついた解決策であり、plistやZwoptexは必要ありませんが、これは各フレームが正確に32x32であり、32間隔で完全に整列していることを前提としています。

@interface GameLevelLayer() 
{
    CCSpriteBatchNode *trexSheet;
    int aniCount;
    NSTimer *autoWalker;


}
@end

initまたはスプライトシートを追加する場所

trexSheet = [CCSpriteBatchNode batchNodeWithFile:@"dinosss.png"];
[self addChild:trexSheet];
aniCount=1;

NSTimerを使用して、アニメーションを停止および開始します

-(void)stopWalker{
        aniCount =1;
//set to start frame
    [self.player setDisplayFrame:
[CCSpriteFrame frameWithTexture:trexSheet.texture rect:
CGRectMake(0,0,32,32)]];

    if (autoWalker){   
    [autoWalker invalidate];
    autoWalker = nil;
    }

}

開始するには...

-(void)startWalker{

if (!autoWalker){ 
   [self walkimate];
    //Change the timeInterval to adjust animation speed
    autoWalker = [NSTimer scheduledTimerWithTimeInterval:0.15
                                             target:self
                                           selector:@selector(walkimate)
                                           userInfo:nil
                                            repeats:YES];
} 
}

ループ関数

-(void)walkimate{
    ///loop through animation
if (aniCount>4) {
    ///set to 0 because we add one at the end before the next call
    aniCount =0;
}

//this finds the 32x32 pa
[self.player setDisplayFrame:
[CCSpriteFrame frameWithTexture:trexSheet.texture rect:
CGRectMake(32*i,0,32,32)];

aniCount++;
}
于 2012-09-30T11:21:23.997 に答える
0

Zwoptexツールを使用して、cocos2DplistでspriteSheetをエクスポートできます。その無料のツールと使いやすい。

于 2012-09-30T03:07:15.537 に答える