zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    用node.js从零开始去写一个简单的爬虫
    如何在手机上查看测试vue-cli构建的项目
    【干货】听说你想成为一名6的飞起的黑客,这些资料怎么能少
    用node.js从零开始去写一个简单的爬虫
    如何在手机上查看测试vue-cli构建的项目
    一个好用的在线微信二维码设计网站
    ES6-----学习系列十五(Iterator)
    js学习总结----js中常用的四种输出方式
    js学习总结----javascript引入到页面的方式和细节
    ES6-----学习系列十四(promise)
  • 原文地址:https://www.cnblogs.com/he-bo/p/9706549.html
Copyright © 2011-2022 走看看