これを行う最も良い方法は、スプライトシートを作成することです。まずはhttp://zwoptexapp.com/を無料で入手し、ココスを使用するためのスプライトシートを作成することができます(輸出業者はcocos2dを選択して適切なplistを作成してください)
1つの大きなテクスチャあなたは、あなたはテクスチャを切り替え
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"your_plist"];
であなたのテクスチャを読み込むことができます(zwoptexがあなたのための両方を作成します)のplistでプロジェクトに
を追加することができますので、内のすべての画像を持つ、遅い操作です同じテクスチャは、あなたがspriのテクスチャを変更した後に、OpenGLのパフォーマンスを向上させますteがFRAME_NAMEがPLIST内のフレームの名前です(あなたはXcodeの内のplistを選択することで、それを見ることができます
[yourSprite setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"FRAME_NAME"]];
非常に簡単です。画像を繰り返すことなく、ランダムな方法で、サイクルに
... (私は、私はクラス宣言とインライン実装:)内のINITやら、ここで直接いくつかの擬似コードを記述します)
//WARNING THIS IS PSEUDO CODE :)
@interface Randomizer {
//an array of NSStrings containing all you images names
NSMutableArray *allImagesFrameNames = [NSMutableArray arrayWithCapacity:NUM_FRAMES];
CCSprite *sprite = alloc init
}
-(void) resetAllFrames {
[allImagesFrameNames removeAllobjects];
[allImagesFrameName addObject:@"FIRST_IMAGE"];
[allImagesFrameName addObject:@"SECOND_IMAGE"]; //add all your images
}
@end
とランダムフレームに表示する:
-(void) display a randomImage {
//if the array is empty, all images are already been randomly displayed, so we reset the array
if([allImagesFrameName count] == 0)
[self resetAllFrames];
//we choose a random index
int randomIndex = arc4random %[allImagesFrameName count];
//we get the frame name at that index
NSString *imageFrameName = [allImagesFrameNames objectAtIndex:randomIndex];
//and we display the frame
[sprite setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:imageFrameName]];
[allImagesFrameNames removeObjectAtIndex:randomIndex];
}
おかげであなたUltrakorneを... :)私は同じことを実装し、あなたに戻ってきましょう。私はそれが私のために働くだろうと思う.. – Sarah