从App Delegate检测Cocos2D场景中的变化

时间:2012-12-27 22:09:32

标签: iphone objective-c ios cocos2d-iphone

如何从App Delegate中检测场景变化? 我有一个主菜单,只有一个按钮,使用cocos2D的菜单系统链接到第二页。

当用户按下按钮时,我将场景从MenuScene转换为GameScene。

是否有可能从app委托中检测到这种转换,以便在场景转换时运行一些代码?

谢谢!

3 个答案:

答案 0 :(得分:1)

您可以使用通知来通知场景已转换。在你的appdelegate的某个地方,听取通知:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doSomethingAfterTransition) name:@"sceneTransitioned" object:nil];

在GameScene的onEnterTransitionDidFinish方法中,您可以发布此通知:

[[NSNotificationCenter defaultCenter] postNotificationName:@"sceneTransitioned" object:nil];

答案 1 :(得分:0)

解决方案可能是每次更改场景时发布通知。

应该为该通知注册应用代表,并在每次更改场景时收到通知。

答案 2 :(得分:0)

你能否使用已经内置CCNode对象的回调(CCScene来自CCNode)......来自CCNode的以下复制粘贴来自版本2.0,但我相信这些方法可以追溯到很久以前。任何coco'onSomething'方法,如果你覆盖它,不要忘记[super onSomething],否则你的里程会有所不同:)

/** Event that is called when the CCNode enters in the 'stage'.
 If the CCNode enters the 'stage' with a transition, this event is called when the transition finishes.
 If you override onEnterTransitionDidFinish, you shall 
 call [super onEnterTransitionDidFinish].
*/

-(void) onEnterTransitionDidFinish;


/** callback that is called every time the CCNode leaves the 'stage'.
 If the CCNode leaves the 'stage' with a transition, this callback is called 
 when the transition starts.
 */
-(void) onExitTransitionDidStart;
相关问题