creater 动画

2019-05-20  本文已影响0人  凡凡的小web

animation组件
1: 代码中获得cc.Animation组件:
  编辑器关联;
  代码获取组件;
2: Animation组件主要的方法:
  play([name], [start_time]), 播放指定的动画,如果没有制定就播放默认的动画;
  playAdditive: 与play一样,但是不会停止当前播放的动画;
  stop([name]): 停止指定的动画,如果没有指定名字就停止当前播放的动画;
  pause/resume: 暂停唤醒动画;
  getClips: 返回组件里面带的AnimationClip数组
3: Animation重要的属性:
  defaultClip: 默认的动画剪辑;
  currentClip: 当前播放的动画剪辑;
4: Animation播放事件: 动画组件对象来监听on,不是节点
  play : 开始播放时 stop : 停止播放时 pause : 暂停播放时 resume : 恢复播放时
  lastframe : 假如动画循环次数大于 1,当动画播放到最后一帧时 finished : 动画播放完成时

动画里面调用代码函数
1:插入一个时间到动画里面;
2: 编辑这个时间触发的函数: 名字 + 参数
3: 遍历当前动画组件所挂节点上面所有的脚本或组件,根据这个名字来触发函数;
  动画编辑器里插入test_anima_event事件,动画节点挂的节点的脚本里就要有 对应名字 的方法才能触发(这种方法容易不知道事件的来源,不推荐)
4: 要慎用,代码和动画之间不易太多的调用;

动画系统支持动态注册回调事件

var animation = this.node.getComponent(cc.Animation);
    // 注册
    animation.on('play', this.onPlay, this);
    // 取消注册
    animation.off('play', this.onPlay, this);
    // 对单个 cc.AnimationState 注册回调
    var anim1 = animation.getAnimationState('anim1');
    anim1.on('lastframe', this.onLastFrame, this);

    // 动态创建 Animation Clip:
    var animation = this.node.getComponent(cc.Animation);
    // frames 这是一个 SpriteFrame 的数组.
    var clip = cc.AnimationClip.createWithSpriteFrames(frames, 17);
    clip.name = "anim_run";
    clip.warpMode = cc.WarpMode.Loop;

    // 添加帧事件
    clip.events.push({
        frame: 1, // 准确的时间,以秒为单位。这里表示将在动画播放到 1s 时触发事件
        func: "frameEvent", // 回调函数名称
        params: [1, "hello"] // 回调参数
    });

    animation.addClip(clip);
    animation.play('anim_run');
上一篇 下一篇

猜你喜欢

热点阅读