0

我有两个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. 但不幸的是,它总是把我带到场景 A 片刻,然后才呈现场景 B。据我了解显示UIViewControllerCocos2D,以便它只能在 viewController 从CCDirector. 所以我需要找到一种CCScene在 viewController 仍然打开时异步替换的方法。有任何想法吗?

4

2 回答 2

0

哦。所以你要做的是你必须从它的父母那里删除所有子视图。然后你可以替换你的ccscene。

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

希望这会帮助你。

于 2013-10-29T04:48:22.020 回答
0

你应该有更好的运气使用 cocos2d-iphone 扩展(https://github.com/cocos2d/cocos2d-iphone-extensions)让它工作。您可以尝试使用一个视频播放器类 (CCVideoPlayer)。

于 2013-10-28T15:27:12.687 回答