sbr*_*bru 5 objective-c cocos2d-iphone uistoryboard xcode-storyboard xcode4.3
我在cocos2d 2.0中创建了一个项目,并希望使用故事板合并主菜单.
我在tinytimgames.com上试过Jerrod Putnam的教程(我无法提供链接,因为每个帖子只允许新用户2个链接,但如果你谷歌"cocos2d storyboard"这是第一个链接)但它不起作用我.我完全遵循它(我认为).我打开了我的cocos2d项目并从他的github,CCViewController.m和.h导入了文件,然后创建了一个新的storyboard文件,并按照教程进行操作.然而,当我运行它时,它只是直接开始我的cocos2d游戏,而不是我刚创建的新菜单.
我也试过这个教程:http: //zackworkshopios.blogspot.com/2012/06/cocos2d-with-storyboard-example.html 但是它再一次对我不起作用,因为我没有(或者不知道在哪里查找/获取libcocos2d.a和libCocosDenshion.a文件.
这是我从fidgetware尝试的另一个教程:http://fidgetware.com/Tutorials/page15/page15.html 我做了这个教程,但我的项目没有一个名为RootViewController(.m或.h)的文件所以我不确定在哪里放置应该进入这些文件的代码.
还有Ray Wenderlich的教程,但他没有使用故事板.
如果有人能给我一个解决方案,为什么这些都不适合我,或者给我一步一步详细介绍如何将故事板纳入我的cocos2d 2.0项目,我会非常感激.另外我的另一个问题是我应该从一个cocos2d 2.0项目开始并整合故事板,还是应该从一个单一视图应用程序项目(或另一个应用程序项目开始?)并合并我的cocos2d 2.0部分.提前致谢!
好吧,我终于在杰罗德·普特南的帮助下弄明白了,所以谢谢Jerrod!首先去他的教程:
http://www.tinytimgames.com/2012/02/07/cocos2d-and-storyboards/
并从github链接下载并导入文件.然后创建CCViewController的子类并将其命名为cocos2dViewController.在cocos2dViewController.h中复制并粘贴这个:
#import "CCViewController.h"
@interface cocos2dViewController : CCViewController
@end
Run Code Online (Sandbox Code Playgroud)
并在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
Run Code Online (Sandbox Code Playgroud)
您会注意到我导入了GamePlay.h,这是因为GamePlay.m是我拥有游戏所有内容的地方.因此,导入游戏的头文件.你也会看到我打电话
if(director.runningScene)
[director replaceScene:[GamePlay scene]];
else
[director pushScene:[GamePlay scene]];
Run Code Online (Sandbox Code Playgroud)
确保将"GamePlay"替换为包含游戏的场景名称.完成后,转到AppDelegate.m并替换您的
application didFinishLaunchingWithOptions
Run Code Online (Sandbox Code Playgroud)
功能与此:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}
Run Code Online (Sandbox Code Playgroud)
你快到了!现在,为您的故事板文件,按照提供的链接关注Putnam的教程.他说"并将其类分配给我们刚创建的类",将其分配给cocos2dViewController.就是这样!运行项目它应该工作,如果不是随意问你有任何问题.
| 归档时间: |
|
| 查看次数: |
3048 次 |
| 最近记录: |