您的位置:首页 > 移动开发 > Cocos引擎

场景编辑器CocosBuilder使用教程

2012-06-20 13:06 369 查看

在使用Cocos2d-iPhone框架开发iOS游戏的时候,对于每一个场景(CCScene)的编辑是比较麻烦的,好在有外国的牛人提供了非常棒的场景编辑器----CocosBuilder。下面我将详细介绍CocosBuilder结合Cocos2d-iPhone框架的使用。

框架:Cocos2d-iPhone v2.0-rc2

工具:CocosBuilder 2.0 beta,Xcode4.3

一、打开Xcode,新建一个cocos2d iOS工程

二、在包含.xcodeproj文件的地方新建一个文件夹,叫CCBuilder吧,然后再在这个新建好的文件夹下建两个文件夹,分别叫Projects和Resources,用于放置CocosBuilder工程和资源文件

三、打开安装好的CocosBuilder,打开File菜单下的New,选择New Project,新建一个CocosBuilder工程,并将这个新建的工程保存到/CCBuilder/Projects文件夹下面。然后打开File菜单下的Project Setting菜单,如下图所示



点击"+"号,分别把/Projects和/Resources文件夹加进来

然后在Publish directory这里,选择之前新建的Xcode工程的资源文件夹

将"Flatten paths when publishing"和"Publish to zip file"勾上,减少生成的文件的体积

全部完成后点击"Done"按钮

四、打开File菜单下的New,选择New File,新建一个CocosBuilder文件,并将这个新建的文件保存到/CCBuilder/Projects文件夹下面,比如这里新建的ccb文件叫StartGame.ccb,现在就可以在Object菜单下选择添加Cocos2d元素了

五、在完成ccb文件的编辑后,点击File菜单下的Publish,这样将会在Xcode工程的资源文件夹下生成一个ccb.zip文件,将这个文件添加到Xcode的引用中,就可以使用了

六、为了解析生成的ccb.zip文件,你需要将附件中的文件添加到Xcode工程中,也就是将 CCBReader(用于读取ccb文件)和SSZipArchive(用于解压缩zip文件)添加进去。并且需要在Xcode工程的build settings下更改Preprocessor Macros,添加一个参数"CCB_ENABLE_UNZIP"

七、在调用cocos2d的中CCFileUtils的[CCFileUtils sharedFileUtils]之前,需要调用一下[CCBFileUtils sharedFileUtils];

director_ = (CCDirectorIOS*) [CCDirector sharedDirector];

director_.wantsFullScreenLayout = YES;

[CCBFileUtils sharedFileUtils];

// Display FSP and SPF

[director_ setDisplayStats:YES];

// 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");

// Create a Navigation Controller with the Director

navController_ = [[UINavigationController alloc] initWithRootViewController:director_];

navController_.navigationBarHidden = YES;

// set the Navigation Controller as the root view controller

/ [window_ setRootViewController:rootViewController_];

[window_ addSubview:navController_.view];

// make main window visible

[window_ makeKeyAndVisible];

// 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];

八、使用ccb文件

[CCBReader unzipResources:@"ccb.zip"];

// Use the CCBReader to load the HelloCocosBuilder scene

// from the ccbi-file.

CCScene* scene = [CCBReader sceneWithNodeGraphFromFile:@"StartGame.ccbi" owner:self];

// Add the scene to the stack. The director will run it when it automatically when the view is displayed.

[director_ pushScene: scene];

这样就可以正常的使用了

本文出自 “空旷的原野” 博客,请务必保留此出处http://1127341.blog.51cto.com/1117341/898754
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: