cocoscreator 第五章 ccnode之action的使用(ccnode四大模块 1、场景树 2、事件响应 3、坐标空间转换 4、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;

// 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);
 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 ####");

// 移动到 目的地,后,隐藏这个物体怎办? // 命令清单, sequence[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);

// 不断的放大缩小    repeatForever
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);

// 匀速的飞过,傻了, 缓动  .easing(cc.easeBackOut()); easing(cc.easeCubicActionOut());
// 回弹
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);
this.node.stopAllActions();
// end 

// 移动了到100, 0,删除  this.node.removeFromParent();
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);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值