cocos creator基礎-cc.Node(四)節點action的使用


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;
13: 需要了解所有常用的cc.easeXXX效果和實際的應用場景

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秒內 旋轉到180度; rotation 180;
        this.node.runAction(rto);
        var rby = cc.rotateBy(1, 75); // 在原來的基礎上,1秒內 變化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);
        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); // 下一個周期執行(下一幀) 不是馬上執行
        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, 一邊,一邊 或者使用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(); // 停止節點所有的動作
        // 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) {

    // },
});

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM