关于cocosbuilder的信息
本文目录一览:
- 1、cocosbuilder与spritebuilder有什么区别
- 2、如何使用Cocosbuilder
- 3、cocosbuilder怎么自定义类
- 4、Cocosbuilder工具中的CCScrollview具体怎样应用
- 5、(一)cocos2dx坑爹之旅--天坑CocosBuilder
- 6、如何在 CocosBuilder里使用时间轴Callback 功能
cocosbuilder与spritebuilder有什么区别
1、支持的平台不一样
cocostudio目前的版本只能在windows下面使用(ps:据说mac版也正在开发之中,所以未来一段时间也可能会有mac版本),而cocosbuilder版本目前只能在mac下使用,所以你可以根据自己目前手里的机器的操作系统来决定使用哪款软件。
2、UI体系不同
cocosbuilder是对cocos2dx本身控件的一些封装,比如基本的CCLayer、CCNode、CCLabelTTF、CCControlButton等控件都可以在cocosbuilder中看到,在程序中,你需要引用ccbi文件,你只需要拿到这些对象的引用即可在程序中设置他们的属性,以及添加一些监听。
但是cocostudio则不然,它封装了自己的一套UI体系,比如出现了UITextButton、UILabel、UIButton等控件,这些控件与cocos2dx中原生的控件不尽相同,所以在程序中使用的时候,起初你会觉得不太适用,仿佛进入了另一种编程环境。但是个人觉得如果你熟悉了之后,还是蛮好用的。
3、开发团队
cocostudio是由cocos2dx作者支持的团队,个人觉得后期cocostudio将是主流。
4、bug
cocostudio目前只有1.0版本,所以其中存在为数不少的bug,并且文档欠缺,而cocosbuilder则相对较为成熟,其中的bug不少太多,文档也比较多。
如何使用Cocosbuilder
我们将创造游戏主角Cocos Dragon。Cocos Dragon有一对很小的翅膀因此他飞不高,所以我们需要让他触碰金币来给他加速上升直到碰到炸弹为止。你可以到youtube看这个游戏的视屏:youtube
本游戏可以在iOS模拟器上运行,游戏通过触摸来操作方向。假如你希望把这个游戏设计运用到你的产品中,我推荐你用重力感应来替换触摸方式。
设置工程
建立新的xcode工程。工程名称:CocosDragon。
下载本教程需要用到的美术资源,解压并加到工程中。
现在我们需要建立游戏相应的CocosBuilder 工程。打开CocosBuilder 选择File -New Project。命名为CocosDragon 保存并把资源文件放到xcode的Resources 文件夹(CocosBuilder的资源在一个名为ccbResources的文件夹)打开theHelloCocosBuilder.ccb文件.我们不会使用HelloCocosBuilder 文件,所以你可以在CocosBuilder文件系统中干掉他。
创建动画类型的主界面
我们将开始制作Cocos Dragon所有的界面文件,然后将界面链接到相应的代码中。首先,我们创建一个主菜单。
在CocosBuilder打开的CocosDragon 工程中选择File-New File。我们将让主界面只支持iPhone,所以在resolutiONs settings(方案设置)中勾选iPhone Portrait ,并确保root object type(根对象类型)为CCLayer 并勾选full screen (全屏)。
点击创建,然后命名为“ MainMenuScene ”并且保存到Resources 文件夹。一个新的空文件MainMenuScene.ccb将在CocosBuilder中开启。
主界面我们会包含一个渐变的背景,一个logo,一个开始游戏的按钮,和几片云彩的动画。首先,让我们开始加入渐变的背景。在窗口顶部的工具栏点击CCLayerGradient 按钮。
我们希望渐变层(gradient layer)充满整个屏幕。选择这个层,设置填充(content size)大小单位为“%”并且设置宽高为100×100.
让我们把颜色修改为其他值以遍更适合我们游戏的主色调。点击开始颜色(start color)和完成颜色( end color)以至RGB值为下图显示这样。
继续添加logo到主界面( menu scene)。在左边的工程视图(project view)中,拖拽logo.png到canvas 区域。你添加的图片就会像如下那样显示:
当启动主选单场景时会有漂亮的动画,但是我们还需要在启动时增加logo的动画。首先,点击canvas 区域下面的时间设置来指定动画的长度。这里我们把动画出现的时间线设置为2秒。
现在,我们把logo视为一个精灵,并设置logo精灵的关键帧(keyframes )。拖拽时间戳到动画完成的地方(我们这个工程就是之前设置的 00:02:00),并且确保logo已经被选定。在动画菜单中选择插入关键帧位置(Keyframe /Position),或者使用快捷键’P’.在时间线界面(timeline view),logo精灵会折叠并显示刚才添加的关键帧。
一旦关键帧插入时间线的节点中,我们节点的位置既可以自动添加新的关键帧。首先,移动时间戳到原点(00:00:00的位置)。然后,拖拽logo到绘图界面( canvas area)的顶部可见区域(你可以在拖拽的时候按住shift按钮以便对齐)。当你正在做以上操作时,一个新的关键帧就被自动添加到时间线的原点处,并且我们在两个关键帧中间生成平滑过渡的所有帧。
你可以点击Play来测试一下这个动画。你也可以移动时间戳来看看每个帧的位置。
这个动画我们完成的很漂亮并且每帧的过渡很平滑,但是让我们再加点料。在关键帧之间右击 插值线(译者注:interpolation line,就是插入了过渡帧的地方)并且选择弹出(Bounce Out)。
cocosbuilder怎么自定义类
使用自定义类
CocosBuilder的使用方法是通过自定义类。在CocosBuilder中选中一个对象并在属性栏中输入自定义类的类名就可以了。记住你的自定义类必须是你选中对象的一个子类(如CCLayer,CCNode等等)
当加载ccbi文件时,你需要定义两个自定义类(也可以是一个)。自定义的Loader类继承自cocos2d::extension::CCLayerLoader。
自定义的Layer类继承自
cocos2d::extension::CCBSelectorResolver
cocos2d::extension::CCBMemberVariableAssigner
cocos2d::extension::CCNodeLoaderListener
在你的自定义Loader类中你需要加入初始化代码:
public:
CCB_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(CustomLayerLoaderClass, loader);
CCB_VIRTUAL_NEW_AUTORELEASE_CREATECCNODE_METHOD(CustomLayerClass));
使用Loader类的loader方法,CCBReader可以初始化你的自定义Layer类。
请注意CCBReader不会使用任何自定义的init方法。如果要使用自定义的init方法,你可以在自定义Layer类的构造函数中调用。
关联成员变量
在ccbi中引用的对象可以在文件被加载时关联为成员变量。这些成员变量可以定义在文档的根节点中,在这种情况下它必须分配一个自定义类。
关联成员变量很简单,只要在头文件中声明它们就可以了。
如果要初始化成员变量,你可以在自定义Layer类中重载onAssignCCBMemberVariable方法并输入代码:
CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "sprtBurst", CCSprite *, this-mSprtBurst);
sprtBurst是在CocosBuilder中定义的属性名。
在CocosBuilder中选择对象,在Code Connections面板下把Don't assign变为Doc root var或者Owner var。然后在右边的文本框中输入成员变量的名字。
Cocosbuilder工具中的CCScrollview具体怎样应用
下面我说一下要注意的问题:
1、首先新建文件啦。我命名为MainMeun.ccb。
之后建议view选择none,这样可以去除模拟器的边框,更加容易可视化编辑
2、添加object
3、首先我添加CCSprite
4、为第一个CCSprite添加背景图,在右边工具栏,选择自己想要的图片。
(注:CocosBuilder1.0有个BUG,你选择的图片只能选择你的ccb文件保存的那个文件夹里的图片)
如:你新建一个ccb文件是保存在test文件夹的,那么你只能往test文件夹里放入图片可让CCSprite能够选择图片,图下是我保存test.ccb的文件夹里面有我的图片,这样CCSprite就可以选择自己想要的图片
这是出来的效果如下图(我添加了CCSprite和一个按钮功能):
5、添加按钮控件,让其有事件触发
这个按钮触发时间我建议真的多看几遍cocosbuilder的例子。不过如果试了几遍的都说不行啊,为什么选择器(Selector)里的函数方法名不见了,明明已经写上去了,但是下次打开不见了,诸如此类的问题。现在打开我的项目,打开我新建的MainMeun.ccb
如果你的按钮事件不成功的话是因为你的Selector下的string/string缺少了函数名,你添加进去就可以用了。
6、同理,我新建多一个ccb,命名为help.ccb,是让响应我们上面设置好的helpButton:,使我们按下help按钮可以跳转页面。
(一)cocos2dx坑爹之旅--天坑CocosBuilder
1、坑爹的CococsBuilder(以后简称CB)。用cb编辑了一个简单的界面,来回折腾了大半天,各种坑爹的错误。最坑的算是这个:
Assertion failed: (ccNodeLoadersIterator != this-mCCNodeLoaders.end()),
我在CB中添加的一个中有个Code Connector:我添加了一个类MainMenuLayer。但是应该是没有实现其对应的功能。编译的时候就出现了上面的错误。我把这个关联类删除了就好了。(见下图红圈中的内容)
参考资料:
如何在 CocosBuilder里使用时间轴Callback 功能
You can use CocosBuilder for creating character animations, animating complete scenes or just about any animation you can imagine. The animation editor has full support for multiple resolutions, easing between keyframes, boned animations and multiple timelines to name a few of the features.
你可以使用CocosBuilder创建角色动画,场景动画或者其他一些动画。动画编辑器完全支持多分辨率,动画关键帧,骨骼动画以及多条时间轴等功能。
The Basics
基础
In the bottom of the main window you can find the timeline. You use the timeline to create your animations.
在下图中你可以看到时间轴,你可以使用时间轴来创建你的动画。
By default your ccb-file has a single timeline that is 10 seconds long. CocosBuilder edits animations at a frame rate of 30 frames per second, but when you play back the animation in your app it will use whatever you have set cocos2d to use (the default in cocos2d is 60 fps). The current time is displayed in the top right corner, and has the format minute:second:frame. The blue vertical line also shows the current time. Click the time display to change the duration of the current timeline.
默认情况下你的ccb文件仅有一条长为10秒钟的时间轴。Cocosbuilder以每秒钟30帧的速率编辑动画,但当你的你的应用中播放动画的时候,动画将以你在cocos2d中设置的速率播放(默认是60fps)。当前的时间在右上角显示出来,格式为分钟:秒:帧。蓝色竖线也显示了当前的所在的时间。点击上方的时间显示(水平进度条)来改变当前时间轴单位时间之间的距离。
Adding Keyframes
添加关键帧
Animations in CocosBuilder are keyframe based. You can add keyframes to different properties of a node and CocosBuilder will automatically interpolate between the keyframes, optionally with different types of easing.
CocosBuilder中的动画是以关键帧为基础的。你可以为节点的不同属性添加关键帧,CocosBuilder会自动地在关键帧中插入不同类型的过渡效果。
To add a keyframe, first expand the view of the node by clicking the triangle to the right of the name of the node. This will reveal all the animatable properties of the node. What can be animated varies slightly depending on what type of node you have selected. Once the properties are visible you can click the property in the timeline with the option key held down. This will create a new keyframe at the time of the click. Alternatively, you can create a new keyframe at the time of the time marker by selecting a node then choosing Insert Keyframe in the Animation menu.
首先通过点击节点名称左边的小三角展开节点。这将把节点中所有可制作动画的属性展现出来。根据你所选择节点类型的不同,可以制作成动画的属性会有少许不同。按住键盘上的option键,点击时间轴上的属性,这将在你当前点击的时间点上建立一个关键帧。或者,选中节点后,你可以通过Animation菜单中的Insert Keyframe(插入关键帧)子菜单来创建一个关键帧。
Keyframes are automatically added at the current time if you transform a node in the canvas area, given that the transformed property already has one or more keyframes in the timeline.
如果你在画布区域对节点进行变形的操作,那么在当前时间点会自动创建一个关键帧。
Editing Keyframes
编辑关键帧
You edit a specific keyframe of a node by moving the time marker to the time of the keyframe and selecting the node. You can focus on a keyframe by double clicking it (which will select the node and move the time marker).
如果你要编辑一个关键帧,你要先选中节点,然后把时间标记移动到关键帧的时间点上。你可以通过双击一个关键帧把它设置为焦点(这个操作会选中节点并移动时间轴)。
You can select keyframes and move them together by dragging a selection box around them. You can also copy and paste keyframes between nodes. Make sure you only have one selected node when pasting the keyframes. The keyframes will be pasted starting at the time of the time marker.
你可以把关键帧进行框选后一起移动。你还可以在节点间拷贝粘贴关键帧。当你粘贴关键帧的时候,确保你只选中了一个节点。
If you have selected a set of keyframes it is possible to reverse the order of them by selecting Reverse Selected Keyframes in the Animation menu. Use the Stretch Selected Keyframes… option to speed up or slow down an animation by a scaling factor.
如果你选中了一组关键帧,那么你可以通过Animation菜单中的Revert Selected Keyframes(反转选定关键帧)子菜单来把它们的顺序反转。通过Stretch Selected Keyframes…(拉伸选定关键帧)子菜单来加速或者减缓你的动画(通过输入缩放系数)。
Importing a Sequence of Images
导入一系列图片
If you have an animation created by sprite frames it can be tedious to move each individual frame to the timeline. CocosBuilder simplifies this process by automatically importing a sequence of images. Select the frames that you want to import in the left hand project view, then select a CCSprite in the timeline. Now choose Create Frames from Selected Resources in the Animation menu. The frames will automatically be created at the start of the marker. If you need to slow down the animation, select the newly created keyframes and use the Stretch Selected Keyframes… command.
如果你的动画是通过一组精灵帧实现的,你可以把每一个单独的帧拖放到时间轴上去,但是CocosBuilder简化了这个过程,你可以一口气导入一系列图片资源。在左侧的项目视图中,选择你想要导入的一系列动画帧的资源图片,在时间轴上选择CCScprite(精灵),然后在Animation菜单中选择Create Frames from Selected Resources子菜单,这些帧会自动地在时间点的起始位置创建。如果你想放慢动画,选择刚刚创建好的关键帧并使用Stretch Selected Keyframes…子菜单来达到这个效果。
Applying Easing
使用关键帧过渡
CocosBuilder offers a carefully selected subset of the easings provided by cocos2d. To apply an easing right click between two keyframes and select the type of easing that you want to apply.
CocosBuilder提供了精心挑选的一组cocos2d的过渡(Easing)效果。在两个关键帧中点击右键然后选择你想要的过渡效果。
Some of the easings have additional options, after the easing has been applied you can right click again and select Easing Setting… from the popup menu.
有一些过渡效果有一些额外的参数,使用过渡效果后你可以再次右键点击并从弹出菜单中选择Easing… Setting(过渡设置)。
Using Multiple Timelines
使用多条时间轴
A very powerful feature of CocosBuilder's animation editor is the ability to have multiple timelines in a single file. You can name the different sequences and play them back from your code by using their name. It's even possible to smoothly transition between the different timelines.
CocosBuilder动画编辑器一项最为强大的功能是在一个文件中使用多条时间轴。你可以为不同的序列命名并在你的代码中通过这个名字来调用这个动画。更牛X的是你可以在不同的时间轴间实现无缝过渡。
To select, add or edit your timelines use the timeline popup menu:
在时间轴的弹出菜单中选择:添加或者是编辑你的时间轴:
In the edit timelines dialog you can get an overview of your timelines, rename them, add new ones and (optionally) set one of the timelines to automatically start playback directly when the ccbi-file is loaded by your app.
在编辑时间轴的对话框中,你会看到你的时间轴的概要信息,你可以重命名,添加一个新的时间轴或者指定其中一个时间轴作为当ccbi文件加载时自动播放的时间轴。
Properties in timelines that do not have keyframes set share their values across timelines. E.g. if you move one node in one timeline it will be moved in all timelines as long as they do not have a keyframe set for the position property. It can sometimes be useful to add a single keyframe to a property just to override the shared value for a specific timeline.
如果一个时间轴的属性上没有设定关键帧,那么它就会被其他时间轴的关键帧所影响,比如:如果你在一个时间轴里移动了一个节点,它也会在所有没有定义位置关键帧的时间轴里面移动。你可以通过给一个时间轴设定一个单帧来避免被其他时间轴的关键帧所覆盖。
Chaining Timelines
链接时间轴
You can automatically play back a sequence of timelines by chaining them. You can also use this feature for automatically looping a timeline.
你可以把多条时间轴链接起来并播放。你也可以利用这个功能来自动地循环播放一条时间轴。
To have a timeline play in sequence, click the No chained timeline text and select the timeline you want to play right after the current one.
如果要使用链接时间轴的功能,点击No chained timeline(无链接时间轴)文字并选择当前时间轴结束后你想继续播放的时间轴。
Playing Back Animations in Code
在代码中播放动画
To programmatically control the animations you create with CocosBuilder you will need to retrieve the CCBAnimationManager. The animation manager will be assigned to the nodes userObject when the ccbi-file is loaded.
为了让CocosBuilder创建的动画在你的代码中播放,你需要使用CCBAnimationManager。在ccbi文件加载时,动画管理器会被指定给userObject节点。
CCNode* myNodeGraph = [CCBReader nodeGraphFromFile:@"myFile.ccbi"];
CCBAnimationManager* animationManager = myNodeGraph.userObject;
The animation manager will be returned as an autoreleased object. To play back a specific timeline call the runAnimationsForSequenceNamed: method. If a timeline is currently playing it will be immediately stopped when calling this method.
动画管理器会返回一个自释放的对象。调用runAnimationsForSequenceNamed:方法来播放一个指定的时间轴。如果一个时间轴已经在播放了,它会被立即停止。
[animationManager runAnimationsForSequenceNamed:@"My Timeline"];
Optionally, you can use a tween duration to smoothly transition to the new timeline. Where possible linear interpolations will be used for the transition.
或者你也可以使用tweenDuration参数平滑地过渡到一个新的时间轴。
[animationManager runAnimationsForSequenceNamed:@"My Timeline" tweenDuration:0.5f];
It is also possible to receive a callback whenever a timeline has finished playing. You will receive these callbacks even if another timeline is chained in sequence. Use the CCBAnimationManagerDelegate to receive the callbacks.
还可以为时间轴播放完毕时设定一个回调函数。就算有另外一个时间轴被链接起来,你还是可以使用这些回调函数。使用CCBAnimationManagerDelegate来接收回调函数。
关于cocosbuilder和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
相关文章
发表评论
评论列表
- 这篇文章还没有收到评论,赶紧来抢沙发吧~