よし、Jerrod Putnam の多くの助けを借りて、やっとそれを理解することができたので、Jerrod に感謝します! まず、彼のチュートリアルにアクセスしてください:
http://www.tinytimgames.com/2012/02/07/cocos2d-and-storyboards/
github リンクからファイルをダウンロードしてインポートします。次に、CCViewController のサブクラスを作成し、cocos2dViewController と呼びます。cocos2dViewController.h で、これをコピーして貼り付けます。
#import "CCViewController.h"
@interface cocos2dViewController : CCViewController
@end
cocos2dViewController.m で、これをコピーして貼り付けます (Putnam のチュートリアルから)
#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's 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's 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
GamePlay.h をインポートしたことに気付くでしょう。これは、GamePlay.m にゲームのすべてのコンテンツがあるためです。そのため、ゲームのヘッダー ファイルをインポートします。また、私が電話することもわかります
if(director.runningScene)
[director replaceScene:[GamePlay scene]];
else
[director pushScene:[GamePlay scene]];
「GamePlay」は、ゲームを含むシーンの名前に置き換えてください。それをしたら、 AppDelegate.m に移動して、
application didFinishLaunchingWithOptions
これで機能します:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}
あなたはもうすぐそこにいます!ストーリーボード ファイルについては、提供されたリンクにある Putnam のチュートリアルに従ってください。彼が「そしてそのクラスを作成したばかりのものに割り当てます」と言ったところで、それを cocos2dViewController に割り当てます。以上です!プロジェクトを実行するとうまくいくはずです。そうでない場合は、お気軽に質問してください。