Working with Animations

动画

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来接收回调函数。

[cocos2dx开发技巧4]工具CocosBuilder的使用–复杂动画

转发,请保持地址:http://blog.csdn.net/stalendp/article/details/8760957

一个网友推荐过一款制作动画的工具,叫做 Spriter; 其中有个Demo介绍怎么制作游戏中的boss,十分精彩;Sprite的Demo地址为:How to use Spriter 0;资源下载地址:Monster;

这篇文章中,我将使用CocosBuilder来复制这个例子,先看截图。

和这个系列之前的文章中一样,先创建cocos2dx工程,命名为Monster,然后在Monster的Resources下建立ccb文件夹,在ccb下创建CocosBuilder工程。然后设置相关属性,拷贝相应的文件。加下来就是cocosBuilder的设计了。

创建File,Root object Type为CCNode,不需要FullScreen, 命名这个文件为monster.ccb:

把相应的13个图片拖动到模拟器中,如下图:

然后调整好位置,图层顺序等,如下图:

接下来的工作就是实现动画了。这里将介绍两个动画,一个是prepare动画,monster在做原地摆臂运动;一个是attack动画,monster将进行一个攻击性动画。

其实动画就是对monster的13个图片进行的Rotate和position等动画设置。(cocosBuilder的详细操作,请参考《[cocos2dx开发技巧2]工具CocosBuilder的使用–集成》)

这里重点介绍attack动画中的头部的动画。头部动画要设计到Rotate,position和frame动画。选择head_0, 在0s,1s处点击r和p按钮,分别创建Rotate和Position的关键帧。然后做相应的调整,在1s只能创建frame动画。如下图:

然后拖动时间轴,查看效果:

创建好attack和prepare动画之后,还要使它们连接起来。attack动画播放完之后,就进入prepare;prepare动画播放完之后接着播放prepare动画(循环播放);具体的时间轴串联,请参考《[cocos2dx开发技巧2]工具CocosBuilder的使用–集成》。

然后创建playground文件,用来测试这个monster。具体如下:

按钮的回调函数设置如下:

导出monster.ccbi, playground.ccbi, 然后在xcode中导入相关文件,就可以进行cocos2dx端的编码了。程序的功能是,当点击btn时,将使prepare状态下的monster进行attack。主要是实现点击按钮的回调函数onAttack。

在xocde中创建Playground类,做如下实现:

class Playground: public CcbBase {
private:CCNode* monster;
public:CCB_STATIC_NEW_AUTORELEASE_OBJECT_WITH_INIT_METHOD(Playground, create);Playground():monster(NULL) {}virtual ~Playground() {CC_SAFE_RELEASE(monster);}bool onAssignCCBMemberVariable(cocos2d::CCObject * pTarget, const char * pMemberVariableName, cocos2d::CCNode * pNode) {CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "monster", CCNode *, this->monster);return NULL;}virtual cocos2d::SEL_MenuHandler onResolveCCBCCMenuItemSelector(cocos2d::CCObject * pTarget, const char * pSelectorName) {CCB_SELECTORRESOLVER_CCMENUITEM_GLUE(this, "onAttack", Playground::onAttack);return NULL;}void onAttack(cocos2d::CCObject *pSender) {CCLOG("attacking");CCBAnimationManager* animationManager = (CCBAnimationManager*)monster->getUserObject();animationManager->runAnimationsForSequenceNamed("attack");  //播放attack动画}};

cocosBuilder播放动画相关推荐

  1. android 自定义view 动画效果,Android自定义view----音乐播放动画

    先给大家看一下效果,因为我也不知道这个东西具体叫什么,标题上面写的是"音乐播放动画",可能描述的不太准确. 效果图.gif 前言 最近项目中做了一个音频播放的功能,播放条上需要一个 ...

  2. Android PowerImageView实现,可以播放动画的强大ImageView

    本文转载自:http://blog.csdn.net/guolin_blog/article/details/11100315 转载请注明出处:http://blog.csdn.net/guolin_ ...

  3. lottie android min sdk,跳一个Lottie无法回调开始播放动画事件的坑

    一.背景介绍 项目背景是在界面中弹出一个浮层动画,同时播放一个音效. 二.当前实现 实现思路比较简单:继承一个DialogFragment,在相关的生命周期方法onViewCreated中调用star ...

  4. 【Playable API】不用Animator如何播放动画?

    你好,我是郑洪智,你可以叫我大智. 先问你一个问题:播放动画不想用Animator搞一堆Animator Controller,怎么做? Unity老玩家可能会先想到:Legacy Animation ...

  5. 安卓ondraw刷新视图_android播放动画时是否会调用被操作的视图的onDraw方法?

    在编写一个自定义视图时由于有一点动画,所以便想到了如果是在播放动画时是否会调用View.onDraw()方法进行更新界面呢? 刚开始我理所当然的觉得是应该需要,因为看起来这个动画的大小和位置和大小过都 ...

  6. unity_AR(一) 安卓手机无法显示模型和无法播放动画问题

    这个星期学习了unity制作MMD动画打包成apk到手机上发现了发现了两个问题 一: 手机无法显示MMD插件渲染的贴图,导致安装到手机上后无法显示模型 解决方法: 把材质球的shader改成这样: t ...

  7. UE4动画重定向与动画蒙太奇(播放动画)

    1.首先选择动画重定向 2/选择要重定向得骨骼,然后选择保存文件夹. 3.在创建好的动画里创建动画蒙太奇 3.点击K播放动画 打开人物蓝图,把创建好的动画蒙太奇添加过去,这样只能添加一个动画. 4.如 ...

  8. Unity Live2D 通过脚本播放动画 Motion Controller 学习使用

    环境: Unity 2019.4.0f1 CubismSdkForUnity-4-r.1 阅读这篇文章可以让你知道:如何让模型播放已设定好的动作 Motion:动作 实际运用:点击人物时人物做各种动作 ...

  9. CSS 帧动画 播放动画

    CSS3 帧动画 amimation @keyframes 在 CSS3 出现之前,动画都是通过 JavaScript 动态的改变元素的样式属性来完成了,这种方式虽然能够实现动画,但是在性能上存在一些 ...

最新文章

  1. 东北农业大学程晓非团队发表植物病毒运动与复制相关综述文章
  2. 基于easyui开发Web版Activiti流程定制器详解(四)——页面结构(下)
  3. WatchDog工作原理
  4. antimalware service executable磁盘占用过多
  5. 摩尔投票法(力扣- -229. 求众数 II)
  6. Bypass WAF实战总结
  7. leetcode 18. 四数之和(双指针)
  8. 嵌入式开发中模拟SPI的驱动
  9. [Objective-C语言教程]数据封装(27)
  10. 高性能mysql_「高性能MySQL」十年阿里架构师推荐,这份高性能MySQL文档送给你
  11. Spring源码学习笔记:起源发展和核心模块主要职能
  12. win11虚拟机如何安装 Windows11虚拟机安装步骤教程
  13. 番茄花园GHOST XP SP3 V1.61 Final纪念版 http://www.ghost2.cn
  14. 械体叶NUNNECH FEWNE OFUEenTM 17.1+教程与算例
  15. arcmap裁剪后的tif保存_在arcgis下如何进行影像图裁剪
  16. allure用例定制参数及报告效果展示
  17. mysql 单表 子查询_04 数据库入门学习-单表查询、多表查询、子查询(示例代码)...
  18. 【CP2K教程(二)】WO3的投影态密度和能带结构
  19. 生活随笔:人心难测,伤心地离开
  20. Sci-Hub创始人收到苹果的通知:2年前就把她的账户数据给了FBI

热门文章

  1. 微信公众号第三方网页授权
  2. 海外APP推送(上篇):厂商通道与谷歌FCM通道的差异
  3. 迟滞比较器电路的分析
  4. 金三银四跳槽涨薪,对标一线互联网大厂面试题
  5. Android 挂逼 修炼之行---解析公众号文章消息和链接文章消息如何自动打开原理
  6. 如何将一首网易云音乐,生成一个音乐二维码?
  7. 华为运营商级路由器配置示例 | L3VdPdNdv4 over SRv6 BE ECMP
  8. codeforce 987c
  9. [uoj389][UNR #3]白鸽【欧拉回路】【射线法】【费用流】
  10. 荣耀平板6鸿蒙os,鸿蒙OS系统百机升级计划表来了,快看看有没有你在用的机型...