/**************************place将节点放置到某个指定位置*********************/
var place = cc.place(100,60);
this.sprite.runAction(place);
/**************************flipX将目标水平翻转,flipY将目标垂直翻转*********************/
var flipX = cc.flipX(true);
var flipY = cc.flipY(true);
/**************************show显示,hide隐藏*********************/
var show = cc.show();
var hide = cc.hide();
/**************************toggleVisibility当节点可见时,运行此动作,则节点会被隐藏*********************/
var toggleVisibility = cc.toggleVisibility();
/**************************removeSelf将正在运行此动作的节点从父节点移除*********************/
var moveSelf = cc.removeSelf();//等同于cc.removeSelf(true);
var moveSelf = cc.removeSelf(false);
/**************************callFunc1回调函数*********************/
var moveTo = cc.moveTo(2,cc.p(100,200));
var callback = cc.callFunc(function (){
console.log("123");
}.bind(this));
this.sprite.runAction(cc.sequence(moveTo,callback));
/**************************callFunc2回调函数*********************/
//callFunc1
var action = cc.sequence(
cc.moveBy(2, cc.p(200, 0)),
cc.callFunc(this.onCallback1.bind(this))
);
var action2 = cc.sequence(
cc.scaleBy(2, 2),
cc.fadeOut(2),
cc.callFunc(this.onCallback2, this)
);
var action3 = cc.sequence(
cc.rotateBy(3, 360),
cc.fadeOut(2),
cc.callFunc(this.onCallback3, this, "Hi!")
);
this.sprite.runAction(action);
this.sprite.runAction(action2);
this.sprite.runAction(action3);
//callFunc2
var action = cc.sequence(cc.moveBy(2.0, cc.p(200, 0)),
cc.callFunc(this.removeFromParentAndCleanup, this.sprite, true));
this.sprite.runAction(action);
//callFunc3
var action = cc.callFunc(function (nodeExecutingAction, value) {
this.control1 = "Value is: " + value;
this.log("Object:" + nodeExecutingAction + ". " + this.control1);
}, this, "Hello world");
this.runAction(action);
//持续动作XXTO和XXBy
//属性变化动作
/**************************moveTo、moveBy移动*********************/
var s = cc.director.getWinSize();
var actionTo = cc.moveTo(2, cc.p(s.width - 40, s.height - 40));
var actionBy = cc.moveBy(1, cc.p(80, 80));
var actionByBack = actionBy.reverse();//反转
this.sprite.runAction(actionTo);
this.sprite.runAction(cc.sequence(actionBy, actionByBack));//序列动作
/**************************scaleTo、scaleBy缩放*********************/
var actionTo = cc.scaleTo(2, 0.5);
var actionBy = cc.scaleBy(2, 2);
var actionBy2 = cc.scaleBy(2, 0.25, 4.5);
this.sprite.runAction(actionTo);
this.sprite.runAction(cc.sequence(actionBy2, cc.delayTime(0.25), actionBy2.reverse()));
this.sprite.runAction(cc.sequence(actionBy, cc.delayTime(0.25), actionBy.reverse()));
/**************************rotateTo、rotateBy旋转*********************/
var actionTo = cc.rotateTo(2, 45);
var actionTo2 = cc.rotateTo(2, -45);
var actionTo0 = cc.rotateTo(2, 0);
this.sprite.runAction(cc.sequence(actionTo, cc.delayTime(0.25), actionTo0));
var actionBy = cc.rotateBy(2, 360);
var actionByBack = actionBy.reverse();
this.sprite.runAction(cc.sequence(actionBy, cc.delayTime(0.25), actionByBack));
this.sprite.runAction(cc.sequence(actionTo2, cc.delayTime(0.25), actionTo0.clone()));
/**************************skewTo、skewBy倾斜*********************/
var actionTo = cc.skewTo(2, 37.2, -37.2);
var actionToBack = cc.skewTo(2, 0, 0);
var actionBy = cc.skewBy(2, 0, -90);
var actionBy2 = cc.skewBy(2, 45.0, 45.0);
var delay = cc.delayTime(0.25);
this.sprite.runAction(cc.sequence(actionTo, delay, actionToBack));
this.sprite.runAction(cc.sequence(actionBy, delay.clone(), actionBy.reverse()));
this.sprite.runAction(cc.sequence(actionBy2, delay.clone(), actionBy2.reverse()));
/**************************jumpTo、jumpBy跳跃*********************/
var actionTo = cc.jumpTo(2, cc.p(300, 300), 50, 4);
var actionBy = cc.jumpBy(2, cc.p(300, 0), 50, 4);
var actionUp = cc.jumpBy(2, cc.p(0, 0), 80, 4);
var actionByBack = actionBy.reverse();
var delay = cc.delayTime(0.25);
this.sprite.runAction(actionTo);
this.sprite.runAction(cc.sequence(actionBy, delay, actionByBack));
var action = cc.sequence(actionUp, delay.clone()).repeatForever();
this.sprite.runAction(action);
/**************************bezierTo、bezierBy贝塞尔曲线*********************/
var delay = cc.delayTime(0.25);
var controlPoints = [ cc.p(0, 374),
cc.p(300, -374),
cc.p(300, 100) ];
var bezierForward = cc.bezierBy(2, controlPoints);
var rep = cc.sequence(bezierForward, delay, bezierForward.reverse(), delay.clone()).repeatForever();
this.sprite.x = 80;
this.sprite.y = 160;
var controlPoints2 = [ cc.p(100, s.height / 2),
cc.p(200, -s.height / 2),
cc.p(240, 160) ];
var bezierTo1 = cc.bezierTo(2, controlPoints2);
var controlPoints3 = controlPoints2.slice();// 从数组中返回选定的数组
this.sprite.x = 400;
this.sprite.y = 160;
var bezierTo2 = cc.bezierTo(2, controlPoints3);
this.sprite.runAction(rep);
this.sprite.runAction(bezierTo1);
this.sprite.runAction(bezierTo2);
//视觉特效动作
/**************************blink闪烁*********************/
var action1 = cc.blink(2, 10);//闪烁时间、闪烁次数
var action2 = cc.blink(2, 5);
this.sprite.runAction(action1);
this.sprite.runAction(action2);
/**************************fadeIn、fadeOut淡入淡出、fadeTo节点的透明度变化*********************/
var delay = cc.delayTime(0.25);
var action1 = cc.fadeIn(1.0);
var action1Back = action1.reverse();
var action2 = cc.fadeOut(1.0);
var action2Back = action2.reverse();
var action3 = cc.fadeTo(2,128);//用2秒的时间将透明度渐变到128
this.sprite.runAction(cc.sequence(action1, delay, action1Back));
this.sprite.runAction(cc.sequence(action2, delay.clone(), action2Back));
/**************************tintTo、tintBy色调变化*********************/
var action1 = cc.tintTo(2, 255, 0, 255);//时间、色调颜色
var action2 = cc.tintBy(2, -127, -255, -127);
var action2Back = action2.reverse();
this.sprite.runAction(action1);
this.sprite.runAction(cc.sequence(action2, cc.delayTime(0.25), action2Back));
/**************************Animation动画1*********************/
//第一种 手工动画
var animation = new cc.Animation();
for (var i = 1; i < 15; i++) {
var frameName = "Images/grossini_dance_" + ((i < 10) ? ("0" + i) : i) + ".png";
animation.addSpriteFrameWithFile(frameName);
}
animation.setDelayPerUnit(2.8 / 14);
animation.setRestoreOriginalFrame(true);
var action = cc.animate(animation);
this.sprite.runAction(cc.sequence(action, action.reverse()));
/**************************animate动画2*********************/
cc.spriteFrameCache.addSpriteFrames("animations/grossini.plist");
var sprite = new cc.Sprite(cc.spriteFrameCache.getSpriteFrame("grossini_dance_01.png"));
sprite.x = size.width / 4 * (i + 1);
sprite.y = size.height / 2;
var animFrames = [];
var str = "";
for (var j = 1; j < 15; j++) {
str = "grossini_dance_" + (j < 10 ? ("0" + j) : j) + ".png";
var frame = cc.spriteFrameCache.getSpriteFrame(str);
animFrames.push(frame);
}
var animation = new cc.Animation(animFrames, 0.3);
sprite.runAction(cc.animate(animation).repeatForever());
sprite.runAction(cc.rotateBy(10, 360).repeatForever());
this.addChild(sprite, 0);
//组合动作
/**************************sequence序列动作*********************/
//简单
var action = cc.sequence(
cc.moveBy(1.5, cc.p(240, 0)),
cc.rotateBy(1.5, 540)
);
this.sprite.runAction(action);
//难点
var action = cc.sequence(
cc.place(cc.p(200, 200)),
cc.show(),
cc.moveBy(1, cc.p(100, 0)),
cc.callFunc(this.onCallback1, this),
cc.callFunc(this.onCallback2.bind(this)),
cc.callFunc(this.onCallback3, this));
this.sprite.runAction(action);
/**************************spawn同时*********************/
var action = cc.spawn(
cc.jumpBy(2, cc.p(300, 0), 50, 4),
cc.rotateBy(2, 720));
this.sprite.runAction(action);
/**************************repeatForever永久循环*********************/
var action = cc.sequence(
cc.delayTime(1),
cc.callFunc(this.repeatForeverAction)); // not passing 'this' since it is not used by the callback func
this.sprite.runAction(action);
/**************************repeatForever永久循环*********************/
var act1 = cc.rotateTo(0.5, 90);
var act2 = cc.rotateTo(0.5, 0);
var seq = cc.sequence(act1, act2);
var seq2 = seq.clone();
this.sprite.runAction(seq.repeatForever());
this.sprite.runAction(seq2.repeat(4));
/**************************reverse倒置*********************/
var jump = cc.jumpBy(2, cc.p(300, 0), 50, 4);
var delay = cc.delayTime(0.25);
var action = cc.sequence(jump, delay, jump.reverse());
this.sprite.runAction(action);
/**************************delayTime延时*********************/
var move = cc.moveBy(1, cc.p(150, 0));
var action = cc.sequence(move, cc.delayTime(2), move.clone());
this.sprite.runAction(action);
/**************************repeat循环*********************/
var a1 = cc.moveBy(1, cc.p(150, 0));
var action1 = cc.sequence(cc.place(cc.p(60, 60)), a1).repeat(3);
var action2 = cc.sequence( a1.clone(), a1.reverse(), cc.delayTime(0.25)).repeatForever();
this.sprite.runAction(action1);
this.sprite.runAction(action2);
/**************************follow跟随*********************/
var move = cc.moveBy(2, cc.p(s.width * 3, 0));
var move_back = move.reverse();
var seq = cc.sequence(move, move_back);
var rep = seq.repeatForever();
this.sprite.runAction(rep);
this.runAction(cc.follow(this.sprite, cc.rect(0, 0, s.width * 2 - 100, s.height)));
//变速动作
//指数缓冲cc.easeExponentialIn/cc.easeExponentialOut/cc.easeExponentialInOut
//Sine缓冲cc.easeSineIn/cc.easeSineOut/cc.easeSineInOut
//弹性缓冲cc.easeElasticIn/cc.easeElasticOut/cc.easeElasticInOut
//跳跃缓冲cc.easeBounceIn/cc.easeBounceOut/cc.easeBounceInOut
//回震缓冲cc.easeBackIn/cc.easeBackOut/cc.easeBackInOut
/**************************speed 线性变速动作*********************/
//用时0.5s,节点旋转-90度,重复4,速度为原来的5倍
var rotate = cc.rotateBy(0.5,-90);
var repeat = rotate.repeatForever();
var speed = cc.speed(repeat,5);
this.sprite.runAction(speed);
/**************************cardinalSplineBy自定义曲线运动*********************/
var winSize = cc.director.getWinSize();
this._drawNode1 = new cc.DrawNode();
this.addChild(this._drawNode1);
this._drawNode1.x = 50;
this._drawNode1.y = 50;
this._drawNode1.setDrawColor(cc.color(255,255,255,255));
this._drawNode2 = new cc.DrawNode();
this.addChild(this._drawNode2);
this._drawNode2.x = winSize.width * 0.5;
this._drawNode2.y = 50;
this._drawNode2.setDrawColor(cc.color(255,255,255,255));
var delay = cc.delayTime(0.25);
var array = [
cc.p(0, 0),
cc.p(winSize.width / 2 - 30, 0),
cc.p(winSize.width / 2 - 30, winSize.height - 80),
cc.p(0, winSize.height - 80),
cc.p(0, 0)
];
var action1 = cc.cardinalSplineBy(2, array, 0);
var reverse1 = action1.reverse();
var seq = cc.sequence(action1, delay, reverse1, delay.clone() );
this.sprite.x = 50;
this.sprite.y = 50;
this.sprite.runAction(seq);
var action2 = cc.cardinalSplineBy(2, array, 1);
var reverse2 = action2.reverse();
var seq2 = cc.sequence(action2, delay.clone(), reverse2, delay.clone());
this.sprite.x = winSize.width / 2;
this.sprite.y = 50;
this.sprite.runAction(seq2);
this._drawNode1.drawCardinalSpline(array, 0, 100, 1);
this._drawNode2.drawCardinalSpline(array, 1, 100, 1);
/**************************catmullRomBy、catmullRomTo卡特摩尔罗曲线 创建一个样条插值轨迹*********************/
var delay = cc.delayTime(0.25);
this.sprite.x = 50;
this.sprite.y = 50;
var array = [
cc.p(0, 0),
cc.p(80, 80),
cc.p(winSize.width - 80, 80),
cc.p(winSize.width - 80, winSize.height - 80),
cc.p(80, winSize.height - 80),
cc.p(80, 80),
cc.p(winSize.width / 2, winSize.height / 2)
];
var action1 = cc.catmullRomBy(3, array);
var reverse1 = action1.reverse();
var seq1 = cc.sequence(action1, delay, reverse1);
this.sprite.runAction(seq1);
var array2 = [
cc.p(winSize.width / 2, 30),
cc.p(winSize.width - 80, 30),
cc.p(winSize.width - 80, winSize.height - 80),
cc.p(winSize.width / 2, winSize.height - 80),
cc.p(winSize.width / 2, 30) ];
var action2 = cc.catmullRomTo(3, array2);
var reverse2 = action2.reverse();
var seq2 = cc.sequence(action2, delay.clone(), reverse2);
this.sprite.runAction(seq2);
this._drawNode1.drawCatmullRom(array,50, 1);
this._drawNode2.drawCatmullRom(array2,50, 1);
/************************targetedAction目标动作*********************/
var jump1 = cc.jumpBy(2, cc.p(0, 0), 100, 3);
var jump2 = jump1.clone();
var rot1 = cc.rotateBy(1, 360);
var rot2 = rot1.clone();
var t1 = cc.targetedAction(this.sprite1, jump2);
var t2 = cc.targetedAction(this.sprite2, rot2);
var seq = cc.sequence(jump1, t1, rot1, t2);
var always = seq.repeatForever();
this.sprite.runAction(always);
/************************easeInOut由慢到快再快到慢*********************/
var move = cc.moveBy(2, cc.p(winSize.width - 80, 0));
var move_ease_inout1 = move.clone().easing(cc.easeInOut(2.0));
var move_ease_inout_back1 = move_ease_inout1.reverse();
var move_ease_inout2 = move.clone().easing(cc.easeInOut(3.0));
var move_ease_inout_back2 = move_ease_inout2.reverse();
var move_ease_inout3 = move.clone().easing(cc.easeInOut(4.0));
var move_ease_inout_back3 = move_ease_inout3.reverse();
var delay = cc.delayTime(0.1);
var seq1 = cc.sequence(move_ease_inout1, delay, move_ease_inout_back1, delay.clone());
var seq2 = cc.sequence(move_ease_inout2, delay.clone(), move_ease_inout_back2, delay.clone());
var seq3 = cc.sequence(move_ease_inout3, delay.clone(), move_ease_inout_back3, delay.clone());
this.sprite.runAction(seq1.repeatForever());
this.sprite.runAction(seq2.repeatForever());
this.sprite.runAction(seq3.repeatForever());
/************************easeExponentialIn由慢至快、easeExponentialOut由快至慢,开始忽然加速*********************/
var move = cc.moveBy(2, cc.p(size.width - 80, 0));
var move_back = move.reverse();
var move_ease_in = move.clone().easing(cc.easeExponentialIn());
var move_ease_in_back = move_ease_in.reverse();
var move_ease_out = move.clone().easing(cc.easeExponentialOut());
var move_ease_out_back = move_ease_out.reverse();
var delay = cc.delayTime(0.1);
var seq1 = cc.sequence(move, delay, move_back, delay.clone());
var seq2 = cc.sequence(move_ease_in, delay.clone(), move_ease_in_back, delay.clone());
var seq3 = cc.sequence(move_ease_out, delay.clone(), move_ease_out_back, delay.clone());
this.sprite.runAction(seq1.repeatForever());
this.sprite.runAction(seq2.repeatForever());
this.sprite.runAction(seq3.repeatForever());
/************************easeExponentialInOut由慢至快再由快至慢,开始忽然加速*********************/
var move = cc.moveBy(2, cc.p(winSize.width - 80, 0));
var move_back = move.reverse();
var move_ease = move.clone().easing(cc.easeExponentialInOut());
var move_ease_back = move_ease.reverse();
var delay = cc.delayTime(0.1);
var seq1 = cc.sequence(move, delay, move_back, delay.clone());
var seq2 = cc.sequence(move_ease, delay.clone(), move_ease_back, delay.clone());
this.sprite.runAction(seq1.repeatForever());
this.sprite.runAction(seq2.repeatForever());
/************************easeSineIn由慢至快、easeSineOut由快至慢*********************/
/************************easeSineInOut由慢至快、由快至慢*********************/
/************************easeElasticIn由慢至快、easeElasticOut由快至慢*********************/
/************************easeElasticInOut由慢至快、由快至慢*********************/
/************************easeBounceIn由慢至快、easeBounceOut由快至慢*********************/
/************************easeBounceInOut由慢至快、由快至慢*********************/
//........
return true;
},
onCallback1:function () {
console.log("onCallback1");
},
onCallback2:function () {
console.log("onCallback2");
},
onCallback3:function () {
console.log("onCallback3");
},
removeFromParentAndCleanup:function (data) {
this.removeFromParent(data);
},
repeatForeverAction:function (sender) {
sender.runAction(cc.sequence(
cc.rotateBy(2, 90).easing(cc.easeElasticInOut(0.5)),
cc.rotateBy(0.5, 90)
).repeatForever()
);
cc.sys.garbageCollect();
},
var place = cc.place(100,60);
this.sprite.runAction(place);
/**************************flipX将目标水平翻转,flipY将目标垂直翻转*********************/
var flipX = cc.flipX(true);
var flipY = cc.flipY(true);
/**************************show显示,hide隐藏*********************/
var show = cc.show();
var hide = cc.hide();
/**************************toggleVisibility当节点可见时,运行此动作,则节点会被隐藏*********************/
var toggleVisibility = cc.toggleVisibility();
/**************************removeSelf将正在运行此动作的节点从父节点移除*********************/
var moveSelf = cc.removeSelf();//等同于cc.removeSelf(true);
var moveSelf = cc.removeSelf(false);
/**************************callFunc1回调函数*********************/
var moveTo = cc.moveTo(2,cc.p(100,200));
var callback = cc.callFunc(function (){
console.log("123");
}.bind(this));
this.sprite.runAction(cc.sequence(moveTo,callback));
/**************************callFunc2回调函数*********************/
//callFunc1
var action = cc.sequence(
cc.moveBy(2, cc.p(200, 0)),
cc.callFunc(this.onCallback1.bind(this))
);
var action2 = cc.sequence(
cc.scaleBy(2, 2),
cc.fadeOut(2),
cc.callFunc(this.onCallback2, this)
);
var action3 = cc.sequence(
cc.rotateBy(3, 360),
cc.fadeOut(2),
cc.callFunc(this.onCallback3, this, "Hi!")
);
this.sprite.runAction(action);
this.sprite.runAction(action2);
this.sprite.runAction(action3);
//callFunc2
var action = cc.sequence(cc.moveBy(2.0, cc.p(200, 0)),
cc.callFunc(this.removeFromParentAndCleanup, this.sprite, true));
this.sprite.runAction(action);
//callFunc3
var action = cc.callFunc(function (nodeExecutingAction, value) {
this.control1 = "Value is: " + value;
this.log("Object:" + nodeExecutingAction + ". " + this.control1);
}, this, "Hello world");
this.runAction(action);
//持续动作XXTO和XXBy
//属性变化动作
/**************************moveTo、moveBy移动*********************/
var s = cc.director.getWinSize();
var actionTo = cc.moveTo(2, cc.p(s.width - 40, s.height - 40));
var actionBy = cc.moveBy(1, cc.p(80, 80));
var actionByBack = actionBy.reverse();//反转
this.sprite.runAction(actionTo);
this.sprite.runAction(cc.sequence(actionBy, actionByBack));//序列动作
/**************************scaleTo、scaleBy缩放*********************/
var actionTo = cc.scaleTo(2, 0.5);
var actionBy = cc.scaleBy(2, 2);
var actionBy2 = cc.scaleBy(2, 0.25, 4.5);
this.sprite.runAction(actionTo);
this.sprite.runAction(cc.sequence(actionBy2, cc.delayTime(0.25), actionBy2.reverse()));
this.sprite.runAction(cc.sequence(actionBy, cc.delayTime(0.25), actionBy.reverse()));
/**************************rotateTo、rotateBy旋转*********************/
var actionTo = cc.rotateTo(2, 45);
var actionTo2 = cc.rotateTo(2, -45);
var actionTo0 = cc.rotateTo(2, 0);
this.sprite.runAction(cc.sequence(actionTo, cc.delayTime(0.25), actionTo0));
var actionBy = cc.rotateBy(2, 360);
var actionByBack = actionBy.reverse();
this.sprite.runAction(cc.sequence(actionBy, cc.delayTime(0.25), actionByBack));
this.sprite.runAction(cc.sequence(actionTo2, cc.delayTime(0.25), actionTo0.clone()));
/**************************skewTo、skewBy倾斜*********************/
var actionTo = cc.skewTo(2, 37.2, -37.2);
var actionToBack = cc.skewTo(2, 0, 0);
var actionBy = cc.skewBy(2, 0, -90);
var actionBy2 = cc.skewBy(2, 45.0, 45.0);
var delay = cc.delayTime(0.25);
this.sprite.runAction(cc.sequence(actionTo, delay, actionToBack));
this.sprite.runAction(cc.sequence(actionBy, delay.clone(), actionBy.reverse()));
this.sprite.runAction(cc.sequence(actionBy2, delay.clone(), actionBy2.reverse()));
/**************************jumpTo、jumpBy跳跃*********************/
var actionTo = cc.jumpTo(2, cc.p(300, 300), 50, 4);
var actionBy = cc.jumpBy(2, cc.p(300, 0), 50, 4);
var actionUp = cc.jumpBy(2, cc.p(0, 0), 80, 4);
var actionByBack = actionBy.reverse();
var delay = cc.delayTime(0.25);
this.sprite.runAction(actionTo);
this.sprite.runAction(cc.sequence(actionBy, delay, actionByBack));
var action = cc.sequence(actionUp, delay.clone()).repeatForever();
this.sprite.runAction(action);
/**************************bezierTo、bezierBy贝塞尔曲线*********************/
var delay = cc.delayTime(0.25);
var controlPoints = [ cc.p(0, 374),
cc.p(300, -374),
cc.p(300, 100) ];
var bezierForward = cc.bezierBy(2, controlPoints);
var rep = cc.sequence(bezierForward, delay, bezierForward.reverse(), delay.clone()).repeatForever();
this.sprite.x = 80;
this.sprite.y = 160;
var controlPoints2 = [ cc.p(100, s.height / 2),
cc.p(200, -s.height / 2),
cc.p(240, 160) ];
var bezierTo1 = cc.bezierTo(2, controlPoints2);
var controlPoints3 = controlPoints2.slice();// 从数组中返回选定的数组
this.sprite.x = 400;
this.sprite.y = 160;
var bezierTo2 = cc.bezierTo(2, controlPoints3);
this.sprite.runAction(rep);
this.sprite.runAction(bezierTo1);
this.sprite.runAction(bezierTo2);
//视觉特效动作
/**************************blink闪烁*********************/
var action1 = cc.blink(2, 10);//闪烁时间、闪烁次数
var action2 = cc.blink(2, 5);
this.sprite.runAction(action1);
this.sprite.runAction(action2);
/**************************fadeIn、fadeOut淡入淡出、fadeTo节点的透明度变化*********************/
var delay = cc.delayTime(0.25);
var action1 = cc.fadeIn(1.0);
var action1Back = action1.reverse();
var action2 = cc.fadeOut(1.0);
var action2Back = action2.reverse();
var action3 = cc.fadeTo(2,128);//用2秒的时间将透明度渐变到128
this.sprite.runAction(cc.sequence(action1, delay, action1Back));
this.sprite.runAction(cc.sequence(action2, delay.clone(), action2Back));
/**************************tintTo、tintBy色调变化*********************/
var action1 = cc.tintTo(2, 255, 0, 255);//时间、色调颜色
var action2 = cc.tintBy(2, -127, -255, -127);
var action2Back = action2.reverse();
this.sprite.runAction(action1);
this.sprite.runAction(cc.sequence(action2, cc.delayTime(0.25), action2Back));
/**************************Animation动画1*********************/
//第一种 手工动画
var animation = new cc.Animation();
for (var i = 1; i < 15; i++) {
var frameName = "Images/grossini_dance_" + ((i < 10) ? ("0" + i) : i) + ".png";
animation.addSpriteFrameWithFile(frameName);
}
animation.setDelayPerUnit(2.8 / 14);
animation.setRestoreOriginalFrame(true);
var action = cc.animate(animation);
this.sprite.runAction(cc.sequence(action, action.reverse()));
/**************************animate动画2*********************/
cc.spriteFrameCache.addSpriteFrames("animations/grossini.plist");
var sprite = new cc.Sprite(cc.spriteFrameCache.getSpriteFrame("grossini_dance_01.png"));
sprite.x = size.width / 4 * (i + 1);
sprite.y = size.height / 2;
var animFrames = [];
var str = "";
for (var j = 1; j < 15; j++) {
str = "grossini_dance_" + (j < 10 ? ("0" + j) : j) + ".png";
var frame = cc.spriteFrameCache.getSpriteFrame(str);
animFrames.push(frame);
}
var animation = new cc.Animation(animFrames, 0.3);
sprite.runAction(cc.animate(animation).repeatForever());
sprite.runAction(cc.rotateBy(10, 360).repeatForever());
this.addChild(sprite, 0);
//组合动作
/**************************sequence序列动作*********************/
//简单
var action = cc.sequence(
cc.moveBy(1.5, cc.p(240, 0)),
cc.rotateBy(1.5, 540)
);
this.sprite.runAction(action);
//难点
var action = cc.sequence(
cc.place(cc.p(200, 200)),
cc.show(),
cc.moveBy(1, cc.p(100, 0)),
cc.callFunc(this.onCallback1, this),
cc.callFunc(this.onCallback2.bind(this)),
cc.callFunc(this.onCallback3, this));
this.sprite.runAction(action);
/**************************spawn同时*********************/
var action = cc.spawn(
cc.jumpBy(2, cc.p(300, 0), 50, 4),
cc.rotateBy(2, 720));
this.sprite.runAction(action);
/**************************repeatForever永久循环*********************/
var action = cc.sequence(
cc.delayTime(1),
cc.callFunc(this.repeatForeverAction)); // not passing 'this' since it is not used by the callback func
this.sprite.runAction(action);
/**************************repeatForever永久循环*********************/
var act1 = cc.rotateTo(0.5, 90);
var act2 = cc.rotateTo(0.5, 0);
var seq = cc.sequence(act1, act2);
var seq2 = seq.clone();
this.sprite.runAction(seq.repeatForever());
this.sprite.runAction(seq2.repeat(4));
/**************************reverse倒置*********************/
var jump = cc.jumpBy(2, cc.p(300, 0), 50, 4);
var delay = cc.delayTime(0.25);
var action = cc.sequence(jump, delay, jump.reverse());
this.sprite.runAction(action);
/**************************delayTime延时*********************/
var move = cc.moveBy(1, cc.p(150, 0));
var action = cc.sequence(move, cc.delayTime(2), move.clone());
this.sprite.runAction(action);
/**************************repeat循环*********************/
var a1 = cc.moveBy(1, cc.p(150, 0));
var action1 = cc.sequence(cc.place(cc.p(60, 60)), a1).repeat(3);
var action2 = cc.sequence( a1.clone(), a1.reverse(), cc.delayTime(0.25)).repeatForever();
this.sprite.runAction(action1);
this.sprite.runAction(action2);
/**************************follow跟随*********************/
var move = cc.moveBy(2, cc.p(s.width * 3, 0));
var move_back = move.reverse();
var seq = cc.sequence(move, move_back);
var rep = seq.repeatForever();
this.sprite.runAction(rep);
this.runAction(cc.follow(this.sprite, cc.rect(0, 0, s.width * 2 - 100, s.height)));
//变速动作
//指数缓冲cc.easeExponentialIn/cc.easeExponentialOut/cc.easeExponentialInOut
//Sine缓冲cc.easeSineIn/cc.easeSineOut/cc.easeSineInOut
//弹性缓冲cc.easeElasticIn/cc.easeElasticOut/cc.easeElasticInOut
//跳跃缓冲cc.easeBounceIn/cc.easeBounceOut/cc.easeBounceInOut
//回震缓冲cc.easeBackIn/cc.easeBackOut/cc.easeBackInOut
/**************************speed 线性变速动作*********************/
//用时0.5s,节点旋转-90度,重复4,速度为原来的5倍
var rotate = cc.rotateBy(0.5,-90);
var repeat = rotate.repeatForever();
var speed = cc.speed(repeat,5);
this.sprite.runAction(speed);
/**************************cardinalSplineBy自定义曲线运动*********************/
var winSize = cc.director.getWinSize();
this._drawNode1 = new cc.DrawNode();
this.addChild(this._drawNode1);
this._drawNode1.x = 50;
this._drawNode1.y = 50;
this._drawNode1.setDrawColor(cc.color(255,255,255,255));
this._drawNode2 = new cc.DrawNode();
this.addChild(this._drawNode2);
this._drawNode2.x = winSize.width * 0.5;
this._drawNode2.y = 50;
this._drawNode2.setDrawColor(cc.color(255,255,255,255));
var delay = cc.delayTime(0.25);
var array = [
cc.p(0, 0),
cc.p(winSize.width / 2 - 30, 0),
cc.p(winSize.width / 2 - 30, winSize.height - 80),
cc.p(0, winSize.height - 80),
cc.p(0, 0)
];
var action1 = cc.cardinalSplineBy(2, array, 0);
var reverse1 = action1.reverse();
var seq = cc.sequence(action1, delay, reverse1, delay.clone() );
this.sprite.x = 50;
this.sprite.y = 50;
this.sprite.runAction(seq);
var action2 = cc.cardinalSplineBy(2, array, 1);
var reverse2 = action2.reverse();
var seq2 = cc.sequence(action2, delay.clone(), reverse2, delay.clone());
this.sprite.x = winSize.width / 2;
this.sprite.y = 50;
this.sprite.runAction(seq2);
this._drawNode1.drawCardinalSpline(array, 0, 100, 1);
this._drawNode2.drawCardinalSpline(array, 1, 100, 1);
/**************************catmullRomBy、catmullRomTo卡特摩尔罗曲线 创建一个样条插值轨迹*********************/
var delay = cc.delayTime(0.25);
this.sprite.x = 50;
this.sprite.y = 50;
var array = [
cc.p(0, 0),
cc.p(80, 80),
cc.p(winSize.width - 80, 80),
cc.p(winSize.width - 80, winSize.height - 80),
cc.p(80, winSize.height - 80),
cc.p(80, 80),
cc.p(winSize.width / 2, winSize.height / 2)
];
var action1 = cc.catmullRomBy(3, array);
var reverse1 = action1.reverse();
var seq1 = cc.sequence(action1, delay, reverse1);
this.sprite.runAction(seq1);
var array2 = [
cc.p(winSize.width / 2, 30),
cc.p(winSize.width - 80, 30),
cc.p(winSize.width - 80, winSize.height - 80),
cc.p(winSize.width / 2, winSize.height - 80),
cc.p(winSize.width / 2, 30) ];
var action2 = cc.catmullRomTo(3, array2);
var reverse2 = action2.reverse();
var seq2 = cc.sequence(action2, delay.clone(), reverse2);
this.sprite.runAction(seq2);
this._drawNode1.drawCatmullRom(array,50, 1);
this._drawNode2.drawCatmullRom(array2,50, 1);
/************************targetedAction目标动作*********************/
var jump1 = cc.jumpBy(2, cc.p(0, 0), 100, 3);
var jump2 = jump1.clone();
var rot1 = cc.rotateBy(1, 360);
var rot2 = rot1.clone();
var t1 = cc.targetedAction(this.sprite1, jump2);
var t2 = cc.targetedAction(this.sprite2, rot2);
var seq = cc.sequence(jump1, t1, rot1, t2);
var always = seq.repeatForever();
this.sprite.runAction(always);
/************************easeInOut由慢到快再快到慢*********************/
var move = cc.moveBy(2, cc.p(winSize.width - 80, 0));
var move_ease_inout1 = move.clone().easing(cc.easeInOut(2.0));
var move_ease_inout_back1 = move_ease_inout1.reverse();
var move_ease_inout2 = move.clone().easing(cc.easeInOut(3.0));
var move_ease_inout_back2 = move_ease_inout2.reverse();
var move_ease_inout3 = move.clone().easing(cc.easeInOut(4.0));
var move_ease_inout_back3 = move_ease_inout3.reverse();
var delay = cc.delayTime(0.1);
var seq1 = cc.sequence(move_ease_inout1, delay, move_ease_inout_back1, delay.clone());
var seq2 = cc.sequence(move_ease_inout2, delay.clone(), move_ease_inout_back2, delay.clone());
var seq3 = cc.sequence(move_ease_inout3, delay.clone(), move_ease_inout_back3, delay.clone());
this.sprite.runAction(seq1.repeatForever());
this.sprite.runAction(seq2.repeatForever());
this.sprite.runAction(seq3.repeatForever());
/************************easeExponentialIn由慢至快、easeExponentialOut由快至慢,开始忽然加速*********************/
var move = cc.moveBy(2, cc.p(size.width - 80, 0));
var move_back = move.reverse();
var move_ease_in = move.clone().easing(cc.easeExponentialIn());
var move_ease_in_back = move_ease_in.reverse();
var move_ease_out = move.clone().easing(cc.easeExponentialOut());
var move_ease_out_back = move_ease_out.reverse();
var delay = cc.delayTime(0.1);
var seq1 = cc.sequence(move, delay, move_back, delay.clone());
var seq2 = cc.sequence(move_ease_in, delay.clone(), move_ease_in_back, delay.clone());
var seq3 = cc.sequence(move_ease_out, delay.clone(), move_ease_out_back, delay.clone());
this.sprite.runAction(seq1.repeatForever());
this.sprite.runAction(seq2.repeatForever());
this.sprite.runAction(seq3.repeatForever());
/************************easeExponentialInOut由慢至快再由快至慢,开始忽然加速*********************/
var move = cc.moveBy(2, cc.p(winSize.width - 80, 0));
var move_back = move.reverse();
var move_ease = move.clone().easing(cc.easeExponentialInOut());
var move_ease_back = move_ease.reverse();
var delay = cc.delayTime(0.1);
var seq1 = cc.sequence(move, delay, move_back, delay.clone());
var seq2 = cc.sequence(move_ease, delay.clone(), move_ease_back, delay.clone());
this.sprite.runAction(seq1.repeatForever());
this.sprite.runAction(seq2.repeatForever());
/************************easeSineIn由慢至快、easeSineOut由快至慢*********************/
/************************easeSineInOut由慢至快、由快至慢*********************/
/************************easeElasticIn由慢至快、easeElasticOut由快至慢*********************/
/************************easeElasticInOut由慢至快、由快至慢*********************/
/************************easeBounceIn由慢至快、easeBounceOut由快至慢*********************/
/************************easeBounceInOut由慢至快、由快至慢*********************/
//........
return true;
},
onCallback1:function () {
console.log("onCallback1");
},
onCallback2:function () {
console.log("onCallback2");
},
onCallback3:function () {
console.log("onCallback3");
},
removeFromParentAndCleanup:function (data) {
this.removeFromParent(data);
},
repeatForeverAction:function (sender) {
sender.runAction(cc.sequence(
cc.rotateBy(2, 90).easing(cc.easeElasticInOut(0.5)),
cc.rotateBy(0.5, 90)
).repeatForever()
);
cc.sys.garbageCollect();
},