How to include storyboards in cocos2d 2.0 project?

I made a project in cocos2d 2.0 and would like to enable the main menu using the storyboard.

I tried Jerrod Putnam's tutorial here on tinytimgames.com (I can’t provide a link because new users are only allowed 2 links per post, but if you google the “cocos2d storyboard” this is the first link) but it didn’t work for me. I followed him for sure (I think). I opened my cocos2d project and imported the files from my github, CCViewController.m and .h, and then created a new storyboard file and went for the tutorial. However, when I started it, it just started right in my cocos2d game, and not in the new menu that I just created.

I also tried this tutorial: http://zackworkshopios.blogspot.com/2012/06/cocos2d-with-storyboard-example.html but once again it didn’t work for me as I don’t have (or don’t know where to find / get) files libcocos2d.a and libCocosDenshion.a.

This is another tutorial I tried from fidgetware: http://fidgetware.com/Tutorials/page15/page15.html I did this tutorial, but my project doesn’t have a file called RootViewController (.m or .h), so I I was not sure where to put the code that should go into these files.

There is also a Ray Wenderlich tutorial, but it does not use storyboards.

If someone can give me a solution why none of them work for me or give me a step-by-step detailed description of how to include storyboards in my cocos2d 2.0 project, I would greatly appreciate it. Another question I have is, should I start with the cocos2d 2.0 project and enable storyboards, or should I start with one app application (or another)? And turn on my cocos2d 2.0 part. Thanks in advance!

+5
source share
3 answers

Well, I finally managed to figure it out with a lot of help from Jerrod Putnam, so thanks Jerrod! First go to his tutorial:

http://www.tinytimgames.com/2012/02/07/cocos2d-and-storyboards/

and download and import files from the github link. Then subclass CCViewController and call it cocos2dViewController. In cocos2dViewController.h copy and paste this:

#import "CCViewController.h" @interface cocos2dViewController : CCViewController @end 

and in cocos2dViewController.m copy and paste this (from Putnam tutorial)

 #import "GamePlay.h" #import "cocos2dViewController.h" @interface cocos2dViewController () @end @implementation cocos2dViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; CCDirector *director = [CCDirector sharedDirector]; if([director isViewLoaded] == NO) { // Create the OpenGL view that Cocos2D will render to. CCGLView *glView = [CCGLView viewWithFrame:[[[UIApplication sharedApplication] keyWindow] bounds] pixelFormat:kEAGLColorFormatRGB565 depthFormat:0 preserveBackbuffer:NO sharegroup:nil multiSampling:NO numberOfSamples:0]; // Assign the view to the director. director.view = glView; // Initialize other director settings. [director setAnimationInterval:1.0f/60.0f]; [director enableRetinaDisplay:YES]; } // Set the view controller as the director delegate, so we can respond to certain events. director.delegate = self; // Add the director as a child view controller of this view controller. [self addChildViewController:director]; // Add the director OpenGL view as a subview so we can see it. [self.view addSubview:director.view]; [self.view sendSubviewToBack:director.view]; // Finish up our view controller containment responsibilities. [director didMoveToParentViewController:self]; // Run whatever scene we'd like to run here. if(director.runningScene) [director replaceScene:[GamePlay scene]]; else [director pushScene:[GamePlay scene]]; } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } @end 

You will notice that I imported GamePlay.h because GamePlay.m is where I have all the content for my game. Therefore, import the header file for your game. You will also see me calling

 if(director.runningScene) [director replaceScene:[GamePlay scene]]; else [director pushScene:[GamePlay scene]]; 

Be sure to replace “GamePlay” with the name of the scene that contains your game. After that, go to your AppDelegate.m and replace

 application didFinishLaunchingWithOptions 

with this:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { return YES; } 

You are almost there! Now for your storyboard file, follow the Putnam manual in the link provided. Where he says "and assigns his class to the one we just created," assign it cocos2dViewController. And this! Run the project and it should work if you cannot ask any questions that you have.

+8
source

You will love me.

follow this guide http://www.tinytimgames.com/2012/02/07/cocos2d-and-storyboards/

then you should install your main bulletin board here.

the trick is to aim your main storyboard in iOS apps at the “project name” / summer / iPhone / iPod section you created. select your person story panel.

then in your AppDelegate.m remove the code so that it looks like this:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { return YES; } 

If you don’t come, I will give you my working source code, just let me know

+3
source

Thanks to bagelboy, I have only one update:

  // Create the OpenGL view that Cocos2D will render to. CCGLView *glView = [CCGLView viewWithFrame:self.view.frame pixelFormat:kEAGLColorFormatRGB565 depthFormat:0 preserveBackbuffer:NO sharegroup:nil multiSampling:NO numberOfSamples:0]; 

For my instance, [[[UIApplication sharedApplication] keyWindow] bounds] did not work, and I used self.view.frame

0
source

Source: https://habr.com/ru/post/951142/


All Articles