Hi, I've been attempting to create a Loading Bar that loads and then displays the loaded scene in Cocos2D. My code first loads a special loadingScreen scene which creates a thread to initialize the coming scene. The coming scene updates the loadingScreen every x amount of %, and when it's done, calls the finished method to display itself on the scene and remove the old scene.
However, while the loading bar does load up, the resulting scene that it loads to has a white box in the center of it (where it's supposed to have a normal sprite icon). The shape is correct as well as the position, but the color is all white.
Here is the code that starts the thread:
Quote:
-(void) loadLayer id)layer
{
CCScene *scene = [CCScene node];
[scene addChild:self];
//LoadingScreen deterimines if the Layer on the scene responds to the Load protocol
//LoadingScreen calls
if ([layer conformsToProtocol:@protocol(Load)]) {
[[CCDirector sharedDirector] replaceScene: scene];
[self updateToPercent:0];
[NSThread detachNewThreadSelector:@selector(initFromLoadingS creen toTarget:layer withObject:self];
} else {
[[CCDirector sharedDirector] replaceScene:scene];
}
}
|
The threaded selector is this:
Quote:
-(void) initFromLoadingScreen LoadingScreen *)ld
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
for (int i = 0; i < 4; i++) {
[ld updateToPercent:i];
[NSThread sleepForTimeInterval:0.5];
}
spritetest = [CCSprite spriteWithFile:@"Icon.png"];
[spritetest setPosition:ccp(512, 384)];
[self addChild:spritetest];
[ld finished:self];
[self scheduleUpdate];
[pool drain];
}
|
And the finished method that should replace the current scene and display the new layer.
Quote:
-(void) finished id)layer
{
@synchronized(self) {
CCScene *scene = [CCScene node];
[scene addChild:layer];
[[CCDirector sharedDirector] replaceScene:scene];
}
}
|