好吧,我设法最终弄清楚了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