在cocos2d中,曾經有一種TextureMgr方法(異步),可以讓您加載圖像供以後使用。現在當我使用TextureMgr時,它說它是未聲明的。它是否被棄用?我在.99.5上。如果它不再可用,什麼取代它?有什麼可以做到這一行相同?TextureMgr發生了什麼?
[[TextureMgr sharedTextureMgr] addImageAsync:...NSString goes here... target:self selector:@selector(method:)];
在cocos2d中,曾經有一種TextureMgr方法(異步),可以讓您加載圖像供以後使用。現在當我使用TextureMgr時,它說它是未聲明的。它是否被棄用?我在.99.5上。如果它不再可用,什麼取代它?有什麼可以做到這一行相同?TextureMgr發生了什麼?
[[TextureMgr sharedTextureMgr] addImageAsync:...NSString goes here... target:self selector:@selector(method:)];
看看CCTextureCache
http://www.cocos2d-iphone.org/api-ref/0.99.5/interface_c_c_texture_cache.html
也許這就是你所期待的。
這個緩存是用來創建任何對象的紋理:例如精靈。您可以使用它來預覽圖像。
編輯: 的CCTextureCache當紋理您創建昂的對象,因爲我說的是使用 - 所以如果紋理已經在高速緩存中的元素創建得多快然後如果你會先加載紋理然後創建一個對象。
例如,如果你正在寫這樣的代碼:
id sprite = [CCSprite spriteWithFile: @"my-file.png"]
和@「我-file.png」紋理不在緩存中就將其裝入第一,這將需要一些時間(更多的只是創建一個對象)。
如果你像這樣寫代碼:
id sprite1 = [CCSprite spriteWithFile: @"my-file.png"];
id sprite2 = [CCSprite spriteWithFile: @"my-file.png"];
然後sprite1將創建緩慢,sprite2更多更快,因爲質地已經在緩存中。
您可以MANUALE添加紋理緩存
[[CCTextureCache sharedTextureCache] addImage: @"my-file.png"];
與此紋理的所有對象的創建將會很快。
當你需要預緩存紋理時,代碼中的常見位置是遊戲加載或級別包加載或級別加載。
此外你是否需要使用它們SimpleAudioEngine單
我認爲你正在尋找[CCSpriteFrameCache sharedSpriteFrameCache]
http://www.cocos2d-iphone.org/api-ref/0.99.5/interface_c_c_sprite_frame_cache.html
啊!,忘了TextureCache,今天早上我回答了。 SpriteFrameCache對於動畫非常有用。 – Bongeh 2011-01-14 15:47:07
感謝您的回答:) – Joethemonkey101 2011-01-14 20:52:45
安德魯幾乎回答了你的問題,可以預先緩存的聲音,我只是想給大家介紹如何使用CCTextureCache和CCSpriteFrameCache的代碼段。紋理緩存加載真實紋理/圖像和精靈幀緩存加載關於紋理的信息(如果您正在加載Sprite表格)。 好的,這裏是示例代碼。
這裏latestBurp1-1.pvr.ccz和burpParticles1-1.png是我的精靈表,他們的信息是(同名).plist文件。
在下面的函數中我加載紋理和spriteFrames(關於紋理的信息)。
另外看看pvr文件和pvr.ccz文件,它們的加載速度比png快得多。
-(void) loadBurpAnimation {
NSString* burpFile;
NSString* burpFilePVR;
NSString* burpParticlesFile;
NSString* burpParticlesFilePVR;
burpFile = @"latestBurp1-1.plist";
burpFilePVR = @"latestBurp1-1.pvr.ccz";
burpParticlesFile = @"burpParticles1-1.plist";
burpParticlesFilePVR = @"burpParticles1-1.png";
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:burpFile texture:[[CCTextureCache sharedTextureCache] addImage:burpFilePVR]];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:burpParticlesFile texture:[[CCTextureCache sharedTextureCache] addImage:burpParticlesFilePVR]];
NSMutableArray *burpFrames = [NSMutableArray array];
for(int i = 231; i <= 268; ++i) {
[burpFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"burp.%d.png", i]]];
}
burpAnim = [[CCAnimation alloc] initWithFrames:burpFrames delay:0.04f];
[burpFrames removeAllObjects];
//Burp Particles
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:burpParticlesFile];
NSMutableArray *burpParticlesFrames = [NSMutableArray array];
for(int i = 3; i <= 37; ++i) {
[burpParticlesFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"Burp_%05d.png", i]]];
}
burpParticlesAnim = [[CCAnimation alloc] initWithFrames:burpParticlesFrames delay:0.04f];
[burpParticlesFrames removeAllObjects];
}
我剛剛給了你很多信息,所以你可能需要谷歌的一些條款。
謝謝安德魯!你還回答了我的另一個問題,哈哈,但你能提供更多的信息嗎?謝謝;) – Joethemonkey101 2011-01-14 20:53:35