1: 掌握動(dòng)畫編輯器與cc.Animation組件的使用;
// 節(jié)點(diǎn)澄阳、動(dòng)畫手报、動(dòng)畫文件的關(guān)系
node : {Animation : {AnimationClip}}
動(dòng)畫編輯器使用
1: 創(chuàng)建一個(gè)節(jié)點(diǎn);
2: 為這個(gè)節(jié)點(diǎn)添加一個(gè)動(dòng)畫組件 cc.Animation;
3: 為這個(gè)動(dòng)畫組件新建一個(gè)動(dòng)畫文件 --> AnimationClip對象;
4: cc.Animation 控制面板的屬性:
(1): default Anim Clip: 默認(rèn)的播放的動(dòng)畫剪輯;
(2): Clips: 動(dòng)畫剪輯的數(shù)組集合
(3): Play onLoad: 是否在加載的時(shí)候開始播放;
?
動(dòng)畫編輯器的原理
1: 時(shí)間軸
2: 在不同的時(shí)刻皿伺,調(diào)整節(jié)點(diǎn)以及孩子節(jié)點(diǎn)的不同的屬性的值万矾,然后創(chuàng)建出補(bǔ)間動(dòng)畫;
3: 節(jié)點(diǎn)調(diào)動(dòng)畫的屬性:
位置, 縮放, 旋轉(zhuǎn), 大小, 顏色, 透明度, 錨點(diǎn), 扭曲, ...;
4: 動(dòng)畫編輯器也可以調(diào)節(jié)節(jié)點(diǎn)的子節(jié)點(diǎn)
5: 動(dòng)畫參數(shù):
Simaple: 1秒多少幀, Speed: 速度,播放速度,越小越慢,
wrapMode: Normal, Loop, PingPong, Reverse, Loop Reverse, PingPongReverse;
6: 動(dòng)畫
(1)添加動(dòng)畫屬性
(2)添加關(guān)鍵幀/刪除關(guān)鍵幀,選到關(guān)鍵幀,在屬性編輯器上編輯和修改;
(3)編輯補(bǔ)間動(dòng)畫曲線路徑;
Animation組件
1: 代碼中獲得cc.Animation組件:
編輯器關(guān)聯(lián);
代碼獲取組件;
2: Animation組件主要的方法:
play([name], [start_time]), 播放指定的動(dòng)畫乐导,如果沒有制定就播放默認(rèn)的動(dòng)畫;
playAdditive: 與play一樣典阵,但是不會(huì)停止當(dāng)前播放的動(dòng)畫;
stop([name]): 停止指定的動(dòng)畫奋渔,如果沒有指定名字就停止當(dāng)前播放的動(dòng)畫;
pause/resume: 暫停喚醒動(dòng)畫;
getClips: 返回組件里面帶的AnimationClip數(shù)組
3: Animation重要的屬性:
defaultClip: 默認(rèn)的動(dòng)畫剪輯;
currentClip: 當(dāng)前播放的動(dòng)畫剪輯;
4: Animation播放事件: 動(dòng)畫組件對象來監(jiān)聽on,不是節(jié)點(diǎn)
play : 開始播放時(shí) stop : 停止播放時(shí) pause : 暫停播放時(shí) resume : 恢復(fù)播放時(shí)
lastframe : 假如動(dòng)畫循環(huán)次數(shù)大于 1,當(dāng)動(dòng)畫播放到最后一幀時(shí) finished : 動(dòng)畫播放完成時(shí)
?
動(dòng)畫里面調(diào)用代碼函數(shù)
1:插入一個(gè)時(shí)間到動(dòng)畫里面;
2: 編輯這個(gè)時(shí)間觸發(fā)的函數(shù): 名字 + 參數(shù)
3: 遍歷當(dāng)前動(dòng)畫組件所掛節(jié)點(diǎn)上面所有的腳本或組件萄喳,根據(jù)這個(gè)名字來觸發(fā)函數(shù);
動(dòng)畫編輯器里插入test_anima_event事件卒稳,動(dòng)畫節(jié)點(diǎn)掛的節(jié)點(diǎn)的腳本里就要有 對應(yīng)名字 的方法才能觸發(fā)(這種方法容易不知道事件的來源,不推薦)
4: 要慎用他巨,代碼和動(dòng)畫之間不易太多的調(diào)用;
cc.Class({
? ? extends: cc.Component,
? ? properties: {
? ? ? ? // foo: {
? ? ? ? // ? ?default: null, ? ? ?// The default value will be used only when the component attaching
? ? ? ? // ? ? ? ? ? ? ? ? ? ? ? ? ? to a node for the first time
? ? ? ? // ? ?url: cc.Texture2D, ?// optional, default is typeof default
? ? ? ? // ? ?serializable: true, // optional, default is true
? ? ? ? // ? ?visible: true, ? ? ?// optional, default is true
? ? ? ? // ? ?displayName: 'Foo', // optional
? ? ? ? // ? ?readonly: false, ? ?// optional, default is false
? ? ? ? // },
? ? ? ? // ...
? ? ? ? // 編輯器里面綁定
? ? ? ? anim: {
? ? ? ? ? ? type: cc.Animation,
? ? ? ? ? ? default: null,
? ? ? ? },
? ? },
? ? // use this for initialization
? ? onLoad: function () {
? ? ? ? var anim_node = this.node.getChildByName("anim");
? ? ? ? this.anim_com = anim_node.getComponent(cc.Animation);
? ? ? ? // 是動(dòng)畫組件cc.Animation組件實(shí)例來監(jiān)聽;
? ? ? ? this.anim_com.on("play", function() {
? ? ? ? ? ? console.log("begin play");
? ? ? ? }.bind(this), this);
? ? },
? ? start: function() {
? ? ? ? // this.anim_com.play("anim_class");
? ? ? ? this.anim_com.play(); // 播放的是defalut clip指向的動(dòng)畫clip
? ? },
? ? // called every frame, uncomment this function to activate update callback
? ? // update: function (dt) {
? ? // },
});
我也創(chuàng)建了個(gè)cocos creator的學(xué)習(xí)交流群歡迎大家一起來學(xué)習(xí)點(diǎn)擊鏈接加入群聊【cocos/unity交流群】