开发者

Cocos2D Director Pause/Resume Issue

I am trying to play a .gif animation in cocos2D. For this i am using the library glgif. Now, to display the animation i am pausing the Director, adding a subview to show the animation and after the animation is done i am resuming the Director. However, I am not able to resume the state of the Director and it shows blank. So I tried this without pausing and resuming this Director and it still did not work.I also tried detaching the director before tha animation and adding it back afterwards and even that did not work.

So is there a way to pause/suspend the Director in the application and开发者_JAVA百科 properly restore is back?

Thanks.

Code sample:

[[Director sharedDirector] pause]; 
[[Director sharedDirector] detach]; 
AppDelegate *del = [[UIApplication sharedApplication] delegate]; 
[del.window addSubview:del.viewController.view]; 
[del.window makeKeyAndVisible]; // this is code to call glgif class and start anim. 
//code to resume the director 
AppDelegate *del = [[UIApplication sharedApplication] delegate]; 
[[Director sharedDirector] resume]; 
[[Director sharedDirector] attachInView:del.window]; 
MScene *m = [MScene node]; 
[[Director sharedDirector] replaceScene:m];


If it's a simple overlay, just pause and do your UIKit calls directly. Like this:

- (void)playerChanged
{
   [[CCDirector sharedDirector] pause];
   UIAlertView *alert = [[[UIAlertView alloc] 
      initWithTitle:NSLocalizedString(@"CHANGEPLAYER", nil) 
      message:nil
      delegate:self 
      cancelButtonTitle:nil 
      otherButtonTitles:NSLocalizedString(@"OK", nil),
      nil
   ] autorelease];
   [alert show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
   (void)alertView;
   (void)buttonIndex;

   [[CCDirector sharedDirector] resume];
}

If you're really taking over the whole window, then dispose of it completely

[[CCDirector sharedDirector] end];

and redo your intialization and call runWithScene when you go back. The detach/attach dance does not seem to work well or consistently.


Its possible some of your errors are as a result of attach/detaching, showing/hiding views. Me and my team only call attachInView once on applicationDidFinishLoading and if we want to change in other views over top of Cocos we use sendToBack or bringToFront calls on the delegate window instance. Might be worth a shot. Let me know if that makes sense or if not I can toss in some sample code.


Not completely sure if it could help here, but it is worth mentioning: CCDirector pause method does not stop animation completely but just slows it. StopAnimation method completely stops it. So maybe stopAnimation/startAnimation instead pause/resume could solve this problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜