我有两个CCScenes
,让我们称他们为A和B.当我在场景A时,我用视频播放器呈现UIViewController
个实例。然后我想从那个UIViewController转移到场景B.这就是我这样做的方式:
- (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右。但不幸的是,它总是把我带到场景A片刻,然后才出现场景B.据我所知,显示UIViewController
块Cocos2D
,以便只有在从CCDirector
移除viewController后才能执行此操作。所以我需要找到一种在viewController仍处于打开状态时异步替换CCScene
的方法。有什么想法吗?
答案 0 :(得分:0)
使用cocos2d-iphone扩展程序(https://github.com/cocos2d/cocos2d-iphone-extensions),你应该有更好的运气。您可以尝试使用视频播放器类(CCVideoPlayer)。
答案 1 :(得分: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]];
希望这会对你有所帮助。