Hi all!
Im using a CCMenu for my game menu, and a CCMenuItem for the items. The problem comes when the player touches an item, for ie "New Game". The selector takes too long (like 2 secs) to fire.
I have added a "Loading..." sprite when the selector is fired , then the initialization for the scene starts, but its being kind of worthless since once the animation starts, the scene is shown, and the player kept waiting for 2 secods for something to happen.
So debbuging this, Ive found that what takes too long is the method to be fired, not the loading animation to run.
Have any of you had a problem like this?
Im using cocos 0.99.4.
Maybe Im doing something wrong, this is part of the code that might be helpful in order to understand my problem:
This is part of the init method:
CCSprite * menuBackground = [[CCSprite alloc] initWithFile:[Utils getResourceFileName:@"menu_background"]];
menuBackground.position = CGPointMake( (self.contentSize.width/2), (self.contentSize.height/2));
[self addChild:menuBackground];
CCMenuItem * newgameitem = [CCMenuItemImage itemFromNormalImage:[Utils getResourceFileName:@"menu_new_game"]
selectedImage:[Utils getResourceFileName:@"menu_new_game"]
target:self
selector:@selector(setNewGame:)];
tempMenu = [CCMenu menuWithItems: newgameitem,nil];
[tempMenu alignItemsVerticallyWithPadding:10];
[self addChild: tempMenu];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:[Utils getResourceFileName:@"loadingFrameSheet"]];
CCSpriteSheet * loadingSpriteSheet = [CCSpriteSheet spriteSheetWithFile:[Utils getResourceFileName:@"loadingSpriteSheet"]];
CGPoint posLoading = CGPointMake(self.contentSize.width/2, [[Utils getResourceFileName:@"loading_y"] floatValue]);
loadingSprite = [[Loading alloc] initWithSpriteSheet:loadingSpriteSheet
InitialPosition:posLoading
ScreenSize:self.contentSize
FrameName:@"loading1.png"];
[self addChild:loadingSpriteSheet];
This is the method SetNewGame
-(void) setNewGame:(id)sender {
loadingSprite.visible=YES;
[loadingSprite startLoading];
[Utils setGameShouldBeRestarted:YES];
[MenuLayer setCurrentScene:[MainScene scene] ];
[[CCDirector sharedDirector] replaceScene:[CCFadeTransition transitionWithDuration:1.0f scene:[MenuLayer getCurrentScene]]];
}
Thanks in advance!