How to replace a scene with a RootViewController?
Here I am again with a cocos2d question please help me out. I have a game setup where I have 6-7 differen开发者_运维问答t scenes and one of the scene is having RootViewController where i am using core-graphics fundas and doing line drawing just like (GLPaint app- provided on iOS Library).So what i want is moving from one scene to another with [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:3 scene:[_ _ _ _ _ _ _ _ _ _]]];
now what am I supposed to write in the blanked space?the scene I am replacing contains RootViewController so please help me out with this.
Whether you want to transition to or from your scene which is a RootViewController I don't think you will be able to use Cocos2D transitions on it. I assume you would want to apply a fade transition on the view of your RootViewController but you will need to use UIKit, probably CoreAnimation to do that. To my knowledge Cocos2D can only use Cocos2D transitions on sprites, layers, etc. Basically anything that is a descendant of the CCNode base class. UIKit is a separate space altogether.
That isn't to say you couldn't do what you want but I believe you need to change your thinking around the problem. One possible solution...
- Create a dummy scene that contains nothing
- When you want to fade to the scene with the view controller fade in the dummy scene
- Apply core animation fade in/out on the view controller
That is very loose pseudo-code but from my experiencing of merging UIKit components with Cocos2D it seems like a good place to start.
EDIT: Code sample for animating your view controller and scene
Animate the dummy scene in Cocos2D which I am a bit rusty on but should be something like this...
CCScene* dummyScene = [CCScene node];
[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:3 scene:dummyScene]];
Now animate the view controller....
[UIButton beginAnimations:nil context:NULL];
... do fade in/out, etc with your view controller ...
[UIView commitAnimations];
Check out the Core Animation Guide for an overview of all the different animation/modifications you can do. I forget how you do fades with it. I think it might be as simple as changing the opacity of the view for your viewController in between the beginAnimations
and commitAnimations
calls. I would say give that a go as your first attempt. You'll likely want to start out with the opacity at 0 so its completely invisible and then transition to 1.0 which should make it completely opaque at least if I understand things correctly. You'll also need to bring the viewController to the front of the view stack likely. There are various methods to do that in the UIView API.
精彩评论