引言
cocos creator基礎(chǔ)cc.Node節(jié)點action的使用?
文末附視頻教程
Action
1: Action類是動作命令,我們創(chuàng)建Action,然后節(jié)點運行action就能夠執(zhí)行Action的動作;
2: Action分為兩類: (1) 瞬時就完成的ActionInstant, (2) 要一段時間后才能完成ActionIntervial;
3: cc.Node runAction: 節(jié)點運行action;
4: cc.moveTo, cc.moveBy To: 目標 By: 變化
5: cc.roateBy, cc.rotateTo,
6: cc.scaleBy, cc.scaleTo,
7: cc.fadeOut(淡出), cc.fadeIn(淡入): cc.fadeTo();
8: cc.callFunc, cc.delayTime
9: cc.sequnce, cc.repeat, cc.repeatForever
10: Action easing(緩動的方式): 加上緩動特效, cc.easeXXXXX查看文檔設(shè)置自己想要的緩動對象
11: stopAction: 停止運行action
12: stopAllActions: 停止所有的action;
13: 需要了解所有常用的cc.easeXXX效果和實際的應(yīng)用場景
cc.Class({
? ? extends: cc.Component,
? ? properties: {
? ? },
? ? // use this for initialization
? ? onLoad: function () {
? ? ? ? // move
? ? ? ? var mto = cc.moveTo(1, cc.p(100, 100)); // cc.moveTo(1, x, y);
? ? ? ? this.node.runAction(mto);
? ? ? ? var mby = cc.moveBy(1, cc.p(100, 100)); // cc.moveBy(1, x, y); 變化多少
? ? ? ? this.node.runAction(mby);
? ? ? ? // rotate
? ? ? ? var rto = cc.rotateTo(1, 180);? // 1秒內(nèi) 旋轉(zhuǎn)到180度; rotation 180;
? ? ? ? this.node.runAction(rto);
? ? ? ? var rby = cc.rotateBy(1, 75); // 在原來的基礎(chǔ)上,1秒內(nèi) 變化75,可正,可負
? ? ? ? this.node.runAction(rby);?
? ? ? ? // scale
? ? ? ? this.node.scale = 2;
? ? ? ? var sto = cc.scaleTo(1, 1.1); // 到1.1倍
? ? ? ? this.node.runAction(sto);
? ? ? ? this.node.scale = 2;
? ? ? ? var sby = cc.scaleBy(1, 1.1); // 原來的基礎(chǔ),變化1.1 * 2
? ? ? ? this.node.runAction(sby);
? ? ? ? // opactify
? ? ? ? var fin = cc.fadeIn(1);
? ? ? ? this.node.opacity = 0; // 透明度 0~255
? ? ? ? this.node.runAction(fin);
? ? ? ? var fout = cc.fadeOut(1);
? ? ? ? this.node.runAction(fout); // 物體還是在的的
? ? ? ? var fto = cc.fadeTo(1, 128); // 半透明
? ? ? ? this.node.runAction(fto);
? ? ? ? // function Action
? ? ? ? var func = cc.callFunc(function() {
? ? ? ? ? ? console.log("call Func actin!!!!!");
? ? ? ? }.bind(this));
? ? ? ? console.log("begin ####");
? ? ? ? this.node.runAction(func); // 下一個周期執(zhí)行(下一幀) 不是馬上執(zhí)行
? ? ? ? console.log("end ####");
? ? ? ? // 移動到 目的地,后,隱藏這個物體怎辦?// 命令清單, [Action1, A2, A3],
? ? ? ? // seq Action
? ? ? ? var m1 = cc.moveTo(1, 100, 100);
? ? ? ? var fout = cc.fadeOut(0.5);
? ? ? ? var seq = cc.sequence([m1, fout]);
? ? ? ? this.node.runAction(seq);
? ? ? ? // 一個節(jié)點可以同時運行多個Action, 一邊,一邊 或者使用cc.spawn
? ? ? ? var m1 = cc.moveTo(1, 100, 100);
? ? ? ? var fout = cc.fadeOut(0.5);
? ? ? ? this.node.runAction(fout);
? ? ? ? this.node.runAction(m1);
? ? ? ? //2
? ? ? ? var action = cc.spawn(m1, fout);
? ? ? ? this.node.runAction(action);
? ? ? ? // 不斷的放大縮小
? ? ? ? var s1 = cc.scaleTo(0.8, 1.1);
? ? ? ? var s2 = cc.scaleTo(0.8, 0.8);
? ? ? ? var seq = cc.sequence([s1, s2]);
? ? ? ? var rf = cc.repeatForever(seq);
? ? ? ? this.node.runAction(rf);
? ? ? ? // 勻速的飛過,傻了, 緩動
? ? ? ? // 回彈
? ? ? ? this.node.y = 0;
? ? ? ? var m = cc.moveTo(1, 100, 0).easing(cc.easeBackOut());
? ? ? ? this.node.runAction(m);
? ? ? ? var r = cc.rotateBy(3, 360).easing(cc.easeCubicActionOut());
? ? ? ? var rf = cc.repeatForever(r);
? ? ? ? this.node.runAction(rf);
? ? ? ? this.node.stopAction(rf); // 停止指定的action
? ? ? ? this.node.stopAllActions(); // 停止節(jié)點所有的動作
? ? ? ? // end?
? ? ? ? // 移動了到100, 0,刪除
? ? ? ? var m = cc.moveTo(1, 100, 0);
? ? ? ? var end_func = cc.callFunc(function() {
? ? ? ? ? ? this.node.removeFromParent();
? ? ? ? }.bind(this));
? ? ? ? var seq = cc.sequence([m, end_func]);
? ? ? ? this.node.runAction(seq);
? ? ? ? // cc.Delay,
? ? ? ? var d1 = cc.delayTime(3);
? ? ? ? var fout = cc.fadeOut(0.5);
? ? ? ? var end_func = cc.callFunc(function() {
? ? ? ? ? ? this.node.removeFromParent();
? ? ? ? }.bind(this))
? ? ? ? var seq = cc.sequence([d1, fout, end_func]);
? ? ? ? this.node.runAction(seq);
? ? },
? ? // called every frame, uncomment this function to activate update callback
? ? // update: function (dt) {
? ? // },
});
視頻教程:
鏈接:https://pan.baidu.com/s/1ViPLuotKXFjhcgVDE5wmnQ
提取碼:3qpr
我也創(chuàng)建了個cocos creator的學(xué)習交流群歡迎大家一起來討論點擊鏈接加入群聊【cocos/unity交流群】