分享免费的编程资源和教程

网站首页 > 技术教程 正文

cocos creator基础-cc.Node(四)节点action的使用

goqiw 2024-10-10 08:11:18 技术教程 29 ℃ 0 评论

引言

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) {

// },

});

视频教程:

链接:https://pan.baidu.com/s/1ViPLuotKXFjhcgVDE5wmnQ

提取码:3qpr

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表