为什么我的UIView中的cocos2D场景没有响应?

时间:2011-11-09 08:57:59

标签: ios uiviewcontroller cocos2d-iphone

我有2个UIViewController在每个UIViewController中实现cocos2d场景。 如果用户点击“Page2”按钮,它将变为第二个View Controller。 如果用户点击第二个视图控制器中的“后退”按钮,它将变为第一个视图控制器。

这是我的“Page2”按钮代码:

[[CCDirector sharedDirector] end];

    p2 = [[Page2ViewController alloc] initWithNibName:@"Page2ViewController" bundle:nil];
    [UIView beginAnimations:@"Page2" context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
    [self.view addSubview:p2.view];
    [UIView commitAnimations];

在此之后,第2页仍在使用cocos2d场景进行响应。如果我按“后退”按钮,我的cocos2d场景将不响应,但没有错误,没有警告,没有任何消息。我试过把NSLog放在viewDidLoad,viewWillAppear,viewDidAppear但是没有传递给我的代码。这是我的“后退”按钮代码:

[[CCDirector sharedDirector] end];

[UIView beginAnimations:@"Back to Home" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view.superview cache:YES];
[self.view removeFromSuperview];
[UIView commitAnimations];

任何想法.....感谢

2 个答案:

答案 0 :(得分:0)

请勿在CCDirector上致电end。相反,请使用stopAnimationstartAnimation临时暂停Cocos2D。我不确定这是否会对您的问题有所帮助,但可能会这样。

答案 1 :(得分:0)

这可能有点好处: -

例如,在第一个按钮上单击,您将转到SecondScene: -

- (无效)buttonClicked_color:(ID)发送方 {

[[CCDirector sharedDirector] pushScene:[CCTransitionFade transitionWithDuration:0.5 scene:[SecondScene node]]];

}

在SecondScene中,想要回到FirstScene: -

- (无效)buttonClicked_alpha:(ID)发送方 {

[[CCDirector sharedDirector] pushScene:[CCTransitionFade transitionWithDuration:0.5 scene:[FirstScene node]]];

}