2013-10-28 61 views
0

我有兩個CCScenes,我們稱他們爲A和B.當我在場景中我用視頻播放器呈現一個UIViewController實例。然後我想從UIViewController的現場B.移動這就是我如何做到這一點:如何在UIViewController提供時替換CCScene?

- (void)videoFinished:(NSNotification *)notification 
{ 
[self presentCurrentActivity]; 

id object = notification.object; 

if ([notification.name isEqualToString:AVPlayerItemDidPlayToEndTimeNotification]) 
    [RAActivityInfoManager setVideoWatched]; 

[[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:object]; 
[[NSNotificationCenter defaultCenter] removeObserver:self name:VIDEO_SKIPPED_NOTIFICATION object:nil]; 

[[CCDirector sharedDirector] dismissViewControllerAnimated:YES completion:nil]; 
} 

- (void)presentCurrentActivity 
{ 
if (currentActivity >= numberOfActivitiesInLesson) 
    currentActivity = 1; 

NSString *className = self.activityNames[currentActivity]; 
Class  class  = NSClassFromString(className); 

[RAActivityInfoManager addSpriteFramesForClass:class]; 

SEL selector = sel_registerName("scene"); 
CCScene *scene = [class performSelector:selector]; 

[[CCDirector sharedDirector] replaceScene:scene]; 
} 

所有我需要的是我的解僱後UIViewController獲取到場景B RIGHT。但不幸的是,它總是把我帶到場景A一會兒,然後纔出現場景B.據我瞭解,顯示UIViewController區塊Cocos2D,以便它只能在從CCDirector中刪除viewController後才起作用。所以我需要找到一種方法來異步替換CCScene而viewController仍然在。有任何想法嗎?

回答

0

Ohk。所以你必須做的是你必須從其父母中刪除所有的子視圖。然後你可以替換你的ccscene。

for (id child in [[[CCDirector sharedDirector] view] subviews]) { 
     [child removeFromSuperview]; 
    } 
[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:0.5 scene:[FirstScreen scene] withColor:ccBLACK]]; 

希望這會幫助你。

相關問題