Cocos Creator动画的几种创建方式

Cocos Creator动画的几种创建方式

 

1.  骨骼动画:以动画文件格式为altas json为例,在节点上面添加组件Spine Skeleton,将资源为atlas的文件直接拖进Skeleton     Data选项:注意Premultiplied Alpha的预乘参数不用勾选,关掉颜色预乘效果

                                                                

 

2. Cocos Creater添加帧动画Animation组件后,则在动画编辑器里面可以看到新建Animation Clip的选项,创建Clip,右键+号添加cc sprite frame, 直接将帧动画资源拖进下面时间帧里面,具体操作参考官方介绍视频。

                                                                    

 

3. 纯代码添加Animation Clip动画,类似于2dx, 缓存精灵帧,运行Animate,下面例子步骤是创建节点,节点添加精灵纹理,动画组件,加入帧动画,播放动画过程

 
/* 动态添加动画代码示例 */

var nodeTest = new cc.Node();

nodeTest.name = 'NodeTest';


var sprite = nodeTest.addComponent(cc.Sprite);

sprite.spriteFrame = new cc.SpriteFrame(cc.url.raw('resources/cubetype1.png'));


nodeTest.parent = this.node;


var animation = nodeTest.addComponent(cc.Animation);


/* 添加SpriteFrame到frames数组 */

var frames = [];

frames[0] = new cc.SpriteFrame(cc.url.raw('resources/cube1_frame1.png'));

frames[1] = new cc.SpriteFrame(cc.url.raw('resources/cube1_frame2.png'));

frames[2] = new cc.SpriteFrame(cc.url.raw('resources/cube1_frame3.png'));

frames[3] = new cc.SpriteFrame(cc.url.raw('resources/cube1_frame4.png'));

frames[4] = new cc.SpriteFrame(cc.url.raw('resources/cube1_frame5.png'));


var clip = cc.AnimationClip.createWithSpriteFrames(frames, 5);

clip.name = 'anim_boom';

clip.wrapMode = cc.WrapMode.Loop;


/* 添加关键帧事件 */

clip.events.push({

frame: 1, // 准确的时间,以秒为单位。这里表示将在动画播放到 1s 时触发事件

func: 'frameEvent', // 回调函数名称

params: [1, 'hello'] // 回调参数

});

animation.addClip(clip);

animation.play('anim_boom');
  1.  

  2.  

 

 

4. 最后一种序列动画也是由代码编写,由官方提供位移,缩放,变形等方式: runAction 

    eg:  this.node.runAction(cc.sequence( cc.fadeOut(1), /*cc.removeSelf(true)传true才彻底从场景中删除,false删除了节点引用 还是存在于场景中 */ cc.callFunc(this.callBack,this, {hello:'world'})));

callBack:function(targetNode, arg){ // targetNode是this.node  arg是{hello:'world'} }

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值