Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Modal or Present a viewController in Cocos2d V3?

How do I present or modal a viewController from a Cocos2d V3 scene?

I am trying to add a Login In ViewController to a game I have created in Cocos2d V3.x that loads from the traditional helloWorldScene but everything I have searched and tried so far hasn't worked. (openGLView, AppController)

I had given up and attempted to add a View instead by adding the following two lines -

LoginViewController  *myView = [[LoginViewController alloc] init];

[[[[CCDirector sharedDirector] view] window] addSubview:myView.view];

This presents the view on top of the scene but setting the anything.delegate = self on anything crashes the App. I assume this is because I am loading a view instead of a viewController which lead to my main question.

Any help would be greatly appreciated!

like image 246
Michael Avatar asked Feb 17 '14 09:02

Michael


1 Answers

I honestly don't know why this wasn't working for me on other attempts but here is my answer for anyone that also spends 3 days trying to find it -

#import "LoginViewController.h"

-(void)loadMyView{
    LoginViewController  *myView = [[LoginViewController alloc] init];
    [[CCDirector sharedDirector] presentModalViewController:myView animated:YES];
}
like image 158
Michael Avatar answered Sep 26 '22 17:09

Michael