私はこれに関連する情報を探すのに数日を費やしました。私自身の経験をあなたと共有します. また、セルがタッチされたときに CCDirector が読み込まれる UITableViewController に読み込まれるゲームを作成しようとしています。これは Game Center のターン制ゲームであるため、その設計 (Words With Friends を考えてみてください) です。これについて私がこれまでに見つけた最良のアプローチは次のとおりです (私は 2.0 で作業していることに注意してください - CCDirector は UIViewController サブクラスです):
AppDelegate.h で、テンプレート コードから作成された CCGLView を保持する新しい ivar を作成します。次に、didFinishLaunching で作成した CCGLView を新しい ivar に割り当てます。これにより、ディレクターは、CCDirector をリロードするたびにビューを再作成しようとする代わりに、最初に作成されたビューを再利用できるようになります。
また、AppDelegate で -setupDirector などと呼ばれる新しいメソッドを作成することも必要です。ここで、ディレクターをセットアップします。これは、CCDirector を再作成するたびに呼び出す必要があります。以下に私のバージョンを掲載しました。CCGLView の ivar は「GLView」と呼ばれることに注意してください。
- (void)setupDirector {
if (![CCDirector sharedDirector]) {
CCLOG(@"Calling setupDirector");
director_ = (CCDirectorIOS*) [CCDirector sharedDirector];
director_.wantsFullScreenLayout = YES;
// Display FSP and SPF
[director_ setDisplayStats:NO];
// set FPS at 60
[director_ setAnimationInterval:1.0/60];
// attach the openglView to the director
[director_ setView:GLView];
// for rotation and other messages
[director_ setDelegate:self];
// 2D projection
[director_ setProjection:kCCDirectorProjection2D];
// [director setProjection:kCCDirectorProjection3D];
// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
if( ! [director_ enableRetinaDisplay:YES] )
CCLOG(@"Retina Display Not supported");
// Default texture format for PNG/BMP/TIFF/JPEG/GIF images
// It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
// You can change anytime.
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
// If the 1st suffix is not found and if fallback is enabled then fallback suffixes are going to searched. If none is found, it will try with the name without suffix.
// On iPad HD : "-ipadhd", "-ipad", "-hd"
// On iPad : "-ipad", "-hd"
// On iPhone HD: "-hd"
CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
[sharedFileUtils setEnableFallbackSuffixes:NO]; // Default: NO. No fallback suffixes are going to be used
[sharedFileUtils setiPhoneRetinaDisplaySuffix:@"-hd"]; // Default on iPhone RetinaDisplay is "-hd"
[sharedFileUtils setiPadSuffix:@"-ipad"]; // Default on iPad is "ipad"
[sharedFileUtils setiPadRetinaDisplaySuffix:@"-ipadhd"]; // Default on iPad RetinaDisplay is "-ipadhd"
// Assume that PVR images have premultiplied alpha
[CCTexture2D PVRImagesHavePremultipliedAlpha:YES];
}
さらに、テンプレートがビュー コントローラーをロードする方法をいくつか変更する必要があります。通常、cocos2D は、director_ をルート ビュー コントローラーとしてナビゲーション コントローラーをセットアップします。ここでは、メニュー ビュー コントローラーを割り当てて初期化し、director_ の代わりに THAT を追加します。
// Create a Navigation Controller with the Director
gamesTVC_ = [[GamesTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
navController_ = [[UINavigationController alloc] initWithRootViewController:gamesTVC_];
navController_.navigationBarHidden = NO;
didFinishLaunching の他のすべては同じままでかまいません。ここで、startGameButtonPressed メソッドの menuViewController で、アプリ インスタンスで新しく作成された setupDirector メソッドを呼び出します。これは次の呼び出しによって参照されます。
AppController *app = (AppController *)[[UIApplication sharedApplication] delegate];
if ([CCDirector sharedDirector].runningScene) {
[[CCDirectorIOS sharedDirector] end];
}
[app setupDirector];
[app.navController pushViewController:app.director animated:YES];
CCDirector がまだ実行されていないことを確認するチェックを含め、実行されている場合は終了します。ゲーム レイヤーで、ビュー コントローラーをポップする必要がある場合は、次のように呼び出すだけです。
AppController *app = (AppController *)[[UIApplication sharedApplication] delegate];
[app.navController popViewControllerAnimated:YES];
[[CCDirector sharedDirector] end];
このフローにより、ナビゲーション コントローラーを自由に使用して、CCDirector でゲーム シーンをプッシュし、UIKit ベースのメイン メニューに戻りたいときにそのビュー コントローラーをポップすることができます。自分のゲームでこれを正しく行うために多くのイライラする時間を費やしてきたので、これがお役に立てば幸いです.