好吧,我設法最終弄清楚了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中。米複製並粘貼(從普特南的教程)
#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]];
確保用包含你的遊戲場景的名稱來代替「遊戲」。一旦你這樣做,去你AppDelegate.m以及與此更換你的
application didFinishLaunchingWithOptions
功能:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}
你幾乎沒有!現在爲你的故事板文件在提供的鏈接中按照Putnam的教程。他在說「並將其類指派給我們剛剛創建的類」時,將其分配給cocos2dViewController。就是這樣!運行該項目,它應該工作,如果不是隨便問你有任何問題。
你可以發佈一個工作項目下載鏈接嗎? – 2013-08-08 12:48:43
@OscarApeland我很抱歉,我從未回覆過你。不幸的是,我不再有這個項目,幾乎不能記得我當時所做的任何事情(現在團結起來)。請接受我的道歉。 – 2016-04-13 20:11:00