SpriteSheetsCCSprite
に手動で追加することはできません。texturepackerを使用してアニメーション化されたスプライトを作成する場合、それもファイルで作成され、そのサイズで画像が読み込まれることを知っていることを願っています。.plist
手動で CCSprite を追加すると、SpriteFramesWithFile
. エラーが発生している可能性があります。
texturepackerを使用せずにアニメーション CCSprite を追加する別の方法
CCSprite *dog = [CCSprite spriteWithFile:@"dog1.gif"];
dog.position = ccp(winSize.width/2, winSize.height/2);
[self addChild:dog z:2];
NSMutableArray *animFrames = [NSMutableArray array];
for( int i=1;i<=5;i++)
{
NSString* file = [NSString stringWithFormat:@"dog%d.gif", i];
CCTexture2D* texture = [[CCTextureCache sharedTextureCache] addImage:file];
CGSize texSize = texture.contentSize;
CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];
[animFrames addObject:frame];
}
CCAnimation * animation = [CCAnimation animationWithSpriteFrames:animFrames];
animation.delayPerUnit = 0.07f;
animation.restoreOriginalFrame = YES;
CCAnimate *animAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:animation]];
[dog runAction:animAction];
上記のコードは、テクスチャパッカーCCSprite
を使用せず にアニメーションを追加する方法を説明しているだけです
ここで画像の配列を変更することもできるので、手動で画像を追加することもできます。