cc.Node—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; 

        var mto = cc.moveTo(1, cc.p(100, 100)); // cc.moveTo(1, x, y);
        this.node.runAction(mto);
        var mby = cc.moveBy(5, 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);
        console.log('初始寬:%f,高:%f', this.node.width, this.node.height); //
        // scale
        this.node.scale = 3;
        var sto = cc.scaleTo(1, 1.5); // 到1.1倍
        this.node.runAction(sto);
        console.log('scaleTo 1.5寬:%f,高:%f', this.node.width, this.node.height); //

        var sby = cc.scaleBy(1, 1.5); // 原來的基礎,變化1.5 * node.scale
        this.node.runAction(sby);
        console.log('scaleBy 1.5寬:%f,高:%f', this.node.width, this.node.height); //
        //this.node.setContentSize();

        // opactify
        console.log('漸顯效果');
        var fin = cc.fadeIn(5); //漸顯效果,返回    ActionInterval,參數 持續時間/秒
        this.node.opacity = 0.5;
        this.node.runAction(fin);
        console.log('漸隱效果');
        var fout = cc.fadeOut(1); //漸隱效果,返回    ActionInterval,參數 持續時間/秒
        this.node.runAction(fout); // 物體還是在的的
        var fto = cc.fadeTo(1, 128); //修改透明度到指定值,返回    ActionInterval,參數 duration、opacity(0-255透明底)
        this.node.runAction(fto);

        // function Action
        var func = cc.callFunc(function() {
            console.log("callFunc at here");
        }.bind(this));

        console.log("begin ####");
        this.node.runAction(func);
        console.log("end ####");

        // 移動到 目的地,后,隱藏這個物體怎辦? // 命令清單(按順序執行action命令) [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();//停止所有Action
        // 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);

 


免責聲明!

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



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