2012-12-27 24 views
0

如何從App Delegate中檢測場景中的更改? 我有一個主菜單,它有一個按鈕,使用cocos2D的菜單系統鏈接到第二個頁面。從應用程序委託中檢測Cocos2D場景中的更改

當用戶按下按鈕,我從MenuScene過渡場景GameScene。

是否可以從應用程序的委託檢測這種轉變,這樣我可以運行一些代碼,當場景轉換?

謝謝!

回答

1

你可以使用的通知,通知現場已經轉變。某處在您的appdelegate,聽通知:

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

在你GameScene的onEnterTransitionDidFinish方法,你可以發佈此通知:

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

謝謝!這工作完美! – wayway

0

一個解決辦法是在張貼的通知每次更改場景。

應用程序的委託應註冊爲通知和接收通知每次場景改變。

0

你能使用已經內置回調CCNode對象(CCScene從CCNode下降)......從CCNode下面複製粘貼是從2.0版本,但我相信這些方法日期早。任何可可'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; 
相關問題