I have two CCScenes
, let's call them A and B. When i'm on the scene A i present an UIViewController
instance with video player. Then i want to move from that UIViewController to the scene B. This is how i do that:
- (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];
}
all that i need is to get onto the scene B RIGHT after dismissing my UIViewController
. But unfortunately it always takes me to the scene A for a moment and only after that the scene B is presented. As far as i understand showing UIViewController
blocks Cocos2D
so that it can act only after the viewController is removed from CCDirector
. So i need to find a way to replace CCScene
asynchronously while the viewController is still on. Any ideas?
Ohk. so what you have to do is you have to remove all sub views from its parents.Then you can replace your ccscene.
Hope this will help you.