我正在使用CCScrollLayer,我想在玩家选择阶段时准备图像。这很简单,但当我滚动舞台时,它执行时间(延迟加载图像)。我在线程中加载的图像没有出现
所以我决定使用NSThread。并且我收到了一条消息:“cocos2d:CCSpriteFrameCache:尝试从cocos2d使用文件'Level3.png'作为纹理”。那么它应该出现。但是我在线程上加载的这些图像不会按我的意思显示。根本不值一提。
-(void) moveToStagePage:(int)page
{
...
[NSThread detachNewThreadSelector:@selector(prepareTexture:) toTarget:self withObject:[NSNumber numberWithInt:page]];
...
}
低于源是准备图像的代码。(线程)
-(void) prepareTexture:(NSNumber*)number
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int _page = [number intValue];
NSLog(@"%d Thread start", _page);
if(loadingTexNum != 0 && (_page + 1) != loadingTexNum)
{
[[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFramesFromFile:[NSString stringWithFormat:@"Level%d.plist", loadingTexNum]];
loadingTexNum = _page + 1;
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:[NSString stringWithFormat:@"Level%d.plist", loadingTexNum]];
}
if(loadingTexNum == 0 && (_page + 1) != loadingTexNum)
{
loadingTexNum = _page + 1;
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:[NSString stringWithFormat:@"Level%d.plist", loadingTexNum]];
}
[NSThread sleepForTimeInterval:10.0];
NSLog(@"%d Thread release", _page);
[pool release];
}
非常感谢..我不知道如何欣赏。非常感谢。 –