1. 程式人生 > >Cocos Creator 系統學習筆記(五)--action的使用

Cocos Creator 系統學習筆記(五)--action的使用

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 // }, // ... }, /**Action * 1: Action類是動作命令,我們建立Action,然後節點執行action就能夠執行Action的動作; 2: Action分為兩類: (1) 瞬時就完成的ActionInstant, (2) 要一段時間後才能完成ActionIntervial; 3: cc.Node runAction: 節點執行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檢視文件設定自己想要的緩動物件 11: stopAction: 停止執行action 12: stopAllActions: 停止所有的action;
*/ 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); // 旋轉到180度; rotation 180;
// this.node.runAction(rto); // var rby = cc.rotateBy(1, 75); // 在原來的基礎上,變化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); // 原來的基礎,變化1.1 * 2 // this.node.runAction(sby); // opactify // var fin = cc.fadeIn(1);//1s // this.node.opacity = 0;//設定起始透明度 // 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); 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);*/ // 一個節點可以同時執行多個Action, 一邊,一邊 /*var m1 = cc.moveTo(1, 100, 100); var fout = cc.fadeOut(0.5); this.node.runAction(fout); this.node.runAction(m1);*/ // 不斷的放大縮小 /*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();*/ // 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); }, });