スプライトシートをループでアニメーション化すると、スプライトがいくつあるのかわからないので、前に数える必要があります。他の何か。スプライトシート内の画像の数をカウントする-cocos2d
どのように画像の数をカウントすることができますか? 、そうする別の方法がありますか? (この機能は、スプライトシートの様々な取得することができます。 私はPLISTを使用していないに今好む。
おかげでたくさん。
-(void)animation
{
WeInAction=1;
//animation
CCSpriteBatchNode *spriteSheet = [ CCSpriteBatchNode batchNodeWithFile:animation];
[self addChild:spriteSheet];
CCSprite *dollSprite = [CCSprite spriteWithTexture:spriteSheet.texture rect:CGRectMake(0, 0, 320, 350)];
[spriteSheet addChild:dollSprite];
spriteSheet.anchorPoint=CGPointMake(0, 30);
CGSize s = [[CCDirector sharedDirector] winSize];
dollSprite.position = ccp(s.width/2,s.height/2);
CCAnimation *dollAnimation = [CCAnimation animation];
[dollAnimation setDelay:0.1f];
int frameCount = 0;
for (int y = 0; y < 5; y++) //cocos add all this frames to memery and then he starts down the action,
{
for (int x = 0; x < 6; x++)
{
CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:spriteSheet.texture rect:CGRectMake(x*320,y*350,320,350)];
[dollAnimation addFrame:frame];
frameCount++;
if (frameCount == 25)
break;
}
}
CCAnimate *Action = [CCAnimate actionWithAnimation:dollAnimation];
id call=[CCCallFunc actionWithTarget:self selector:@selector(finishAnimation)];
id sequence=[CCSequence actions:Action,[CCHide action],call,nil];
[dollSprite runAction:sequence];
NSLog(@"%@",basic_pic);
}
私はあなたを理解できませんでした。説明できますか ?私はxとyのループを実行しています。これは前にその値を知ることはできません。それを知る方法はありますか?私はそれが取得する任意のスプライトシートに収まる一般的なループを実行する必要があります。 – Curnelious
Cocos2Dは画像を検査しません。 Cocos2Dは、スプライトシートに複数のイメージがあることを知っている場合にのみ、そのスプライトシートに複数のイメージがあることを認識します。実際には、あなたが指示しない限り、通常のイメージとスプライトシートの違いは分かりません。すべての画像が常に同じ大きさであれば、それを自分で計算するか、またはプラグインした値に基づいて計算する方法を作成することができます。 –
これを知る方法を見つけることはできません。一般的な方向性 ?ココスは "盲目"で、ループ番号を超えて走っています。 – Curnelious