cocos2d-x 3.1.1 学习笔记[3]Action 动作
这些动画貌似都非常多的样子,就所有都创建一次。
代码例如以下:
/* 动画*/
auto sp = Sprite::create("card_bg_big_26.jpg");
Size size = Director::getInstance()->getWinSize();
sp->setScale(0.2);
sp->setPosition(Vec2(size.width / 2 + 200, size.height / 2 + 200));
sp->setAnchorPoint(Vec2(0.5, 0.5));
addChild(sp); /*
* 一般函数都会有xxxTo 和 xxxBy两个方法。
* By方法一般和To方法的作用是一样的。仅仅是By方法能够获得该方法的反向动作。 e.g:moveBy->reverse();
* 动画里面的duration都是表示动画要运行的时间
*/ /**
* MoveTo::create(float duration, const cocos2d::Vec2 &position);
* position : 要移动到的位置
*/
auto a1 = MoveTo::create(2, Vec2(100, 100));//在规定时间内移动到指定的坐标 /**
* JumpTo::create(float duration, const cocos2d::Vec2 &position, float height, int jumps);
* position : 要跳到的位置
* height : 每次跳的高度
* jumps: 要跳的次数
*/
auto a2= JumpTo::create(3, Vec2(0, 0), 30, 6);//跳6下后跳到指定的坐标 /**
* 两秒内放大到1
* ScaleTo::create(float duration, float s)
* s: 要缩放的倍数
*/
auto a3 = ScaleTo::create(2, 1); /**
* 淡入。改变的是opacity这个属性的值。0(看不见)-100(全然看的见)
* FadeIn::create(float d)
* d : 淡入的时间
*/
auto a4 = FadeIn::create(2); /**
* 淡出,改变的是opacity这个属性的值。 0(看不见)-100(全然看的见)
* FadeOut::create(float d)
* d : 淡出的时间
*/
auto a5 = FadeOut::create(2);//2秒淡出 /**
* CardinalSplineTo就好像是运行了多个moveto函数
* CardinalSplineTo::create(float duration, cocos2d::PointArray *points, float tension)
* points: 须要经过的点
* tension: 张力(张力大的话会有回力)
*/
PointArray* arr = PointArray::create(20);
arr->addControlPoint(Vec2(0, 0));
arr->addControlPoint(Vec2(600, 700));
arr->addControlPoint(Vec2(200,200));
arr->addControlPoint(Vec2(55, 55));
auto a6 = CardinalSplineTo::create(5, arr, 20);//相当于多个moveto,20是张力。张力大的话会有回力。 /**
* 旋转一个精灵的角度
* RotateTo::create(float duration, float deltaAngle)
* deltaAngel: 须要旋转的顺时针角度
*/
auto a7 = RotateTo::create(2, 50); /**
* 倾斜一个精灵的
* SkewTo::create(float t, float sx, float sy);
* sx: x轴倾斜的角度
* sy: y轴倾斜的角度
*/
auto a8 = SkewTo::create(3, 20, 1); /**
* 贝塞尔曲线运动
* BezierTo::create(float t, const ccBezierConfig &c)
* c: 贝塞尔參数
*/
ccBezierConfig bezierCon;
bezierCon.controlPoint_1 = Vec2(100, 100);
bezierCon.controlPoint_2 = Vec2(200, 200);
bezierCon.endPosition = Vec2(300, 600);
auto a9 = BezierTo::create(5, bezierCon); /**
* 色彩变幻动作,颜色成分为(0-255),设置(255,255。255)为原画
* TintBy::create(float duration, GLshort deltaRed, GLshort deltaGreen, GLshort deltaBlue)
* deltaRed: 红色成分
* deltaGreen: 绿色成分
* deltaBlue: 蓝色成分
*/
auto a10 = TintBy::create(1, 155, 155, 155); /**
* 让一个精灵在规定的时间内闪烁数次
* Blink::create(float duration, int blinks)
* blinks: 闪烁的次数
*/
auto a11 = Blink::create(1, 5); /**
* 延迟五秒钟,一般用于动画连续播出的时候,歇息五秒钟。在播放下一个动画。
* DelayTime::create(float d)
* d: 须要延迟的时间
*/
auto a12 = DelayTime::create(5); /**
* 创建一个球面坐标轨迹进行旋转的动作
* OrbitCamera::create(float t, float radius, float deltaRadius, float angleZ, float deltaAngleZ, float angleX, float deltaAngleX)
* radius: 起始半径
* deltaRadius: 半径差
* angelZ: 起始z角
* deltaAngleZ: 旋转z角差
* angleX: 起始x角
* deltaAngleX: 旋转x角的差
*/
auto a13 = OrbitCamera::create(5, 10, 0, 45, 180, 90, 0); /**
* 创建一个尾随动作
* Follow::create(cocos2d::Node *followedNode)
* followedNode: 须要尾随的节点
*/
auto a14 = Follow::create(sp); /**
* 让目标动作赋予反弹力,在目标动作过程中会反弹,结束点不反弹。
* EaseBounceIn::create(cocos2d::ActionInterval *action)
* action: 目标动作
*/
auto a15 = EaseBounceIn::create(a1); /**
* 让目标动作赋予反弹力。且以目标动作结束位子開始反弹。(这个效果相比于In要更像反弹力)
* EaseBounceOut::create(cocos2d::ActionInterval *action)
* action: 目标动作
*/
auto a16 = EaseBounceOut::create(a1); /**
* 让目标动作赋予反弹力,结合EaseBounceIn和EaseBounceOut,在过程和结束点都反弹。
* EaseBounceInOut::create(cocos2d::ActionInterval *action)
* action: 目标动作
*/
auto a17 = EaseBounceInOut::create(a1); /**
* 让目标动作赋予回力(方向与要移动方向相反)(在动作開始之前)
* EaseBackIn::create(cocos2d::ActionInterval *action)
* action: 目标动作
*/
auto a18 = EaseBackIn::create(a1); /**
* 让目标动作赋予回力 (方向与要移动方向同样)(在动作结束时)
* EaseBackOut::create(cocos2d::ActionInterval *action)
* action: 目标动作
*/
auto a19 = EaseBackOut::create(a1); /**
* 让目标动作赋予回力 结合EaseBackIn和EaseBackOut
* EaseBackInOut::create(cocos2d::ActionInterval *action)
* action: 目标动作
*/
auto a20 = EaseBackInOut::create(a1); /**
* 赋予动作弹性(移动过程中展示)
* EaseElasticIn::create(cocos2d::ActionInterval *action, float period)
* action: 目标动作
* period: 频率。弹性展示的频率。period秒运行一次弹性效果
*/
auto a21 = EaseElasticIn::create(a1, 0);
a21 = EaseElasticIn::create(a1);//也能够不填写period函数创建 /**
* 赋予动作弹性(移动结束展示)
* EaseElasticOut::create(cocos2d::ActionInterval *action, float period)
* action: 目标动作
* period: 频率,弹性展示的频率,period秒运行一次弹性效果
*/
auto a22 = EaseElasticOut::create(a1, 1);
a22 = EaseElasticOut::create(a1);//也能够不填写period函数创建 /**
* 赋予动作弹性 过程中和结束的时候 EaseElasticIn + EaseElasticOut
* EaseElasticInOut::create(cocos2d::ActionInterval *action, float period)
* action: 目标动作
* period: 频率,弹性展示的频率,period秒运行一次弹性效果
*/
auto a23 = EaseElasticInOut::create(a1, 1);
a23 = EaseElasticInOut::create(a1);//也能够不填写period函数创建 /**
* 让目标动作缓慢開始
* EaseExponentialIn::create(cocos2d::ActionInterval *action)
* action: 目标动作
*/
auto a24 = EaseExponentialIn::create(a1); /**
* 让目标动作缓慢结束
* EaseExponentialOut::create(cocos2d::ActionInterval *action)
* action: 目标动作
*/
auto a25 = EaseExponentialOut::create(a1); /**
* 让目标动作缓慢開始和结束
* EaseExponentialInOut::create(cocos2d::ActionInterval *action)
* action: 目标动作
*/
auto a26 = EaseExponentialInOut::create(a1); /**
* 让目标动作运行速度加倍
* Speed::create(cocos2d::ActionInterval *action, float speed)
* speed: 倍数
*/
auto a27 = Speed::create(a1, 20); /**
* 让多个动画同一时候运行
* Spawn::create(cocos2d::FiniteTimeAction *action1, ..., NULL)
* action: 动作
*/
auto a28 = Spawn::create(a1, a2, NULL); /**
* 让多个动画按顺序运行
* Sequence::create(cocos2d::FiniteTimeAction *action1, ..., NULL)
* action: 动作
*/
auto a29 = Sequence::create(a1, a2, NULL); /**
* 让一个动画运行多次
* Repeat::create(cocos2d::FiniteTimeAction *action, unsigned int times)
* action: 动作
* times: 反复动作次数
*/
auto a30 = Repeat::create(a11, 2); /**
* 对目标动作进行永久性的反复运动
* RepeatForever::create(cocos2d::ActionInterval *action)
* action: 动作
*/
auto a31 = RepeatForever::create(a11); /*
CC_CALLBACK_ 的宏定义中后面的 0 1 2 3分别表示的是 不事先指定回调函数參数的个数。
比如说 CC_CALLBACK_ 1 表示的是。回调函数中不事先指定參数是一个,而事先指定的回调函数的參数 能够随意多个。
*/
sp->setTag(5201314);
//创建一个无參回调函数
auto callFunc = CallFunc::create(CC_CALLBACK_0(HelloWorld::noParam, this));
//创建仅仅有一个參数的回调函数。 (使用默认回调函数)
auto callFuncN = CallFuncN::create(CC_CALLBACK_1(HelloWorld::oneParam, this));
//创建仅仅有一个參数的回调函数。(使用自己定义參数)
auto callFuncNSelf = CallFuncN::create(CC_CALLBACK_0(HelloWorld::oneParamBySelf, this,998));
//创建一个有两个參数的回调函数
auto callFuncND = CallFuncN::create(CC_CALLBACK_1(HelloWorld::twoParam, this, 6)); sp->runAction(callFuncND);
上面最后回调用到的函数:
void HelloWorld::noParam()
{
log("no param");
}
void HelloWorld::oneParamBySelf(int num)
{
log("one param one is %d", num);
}
void HelloWorld::oneParam(Node* node)
{
//传进来的是运动的那个Node
log("one :%d",node->getTag());
}
void HelloWorld::twoParam(Node* node,int sec)
{
log("sec : %d", (int)sec);
}
cocos2d-x 3.1.1 学习笔记[3]Action 动作的更多相关文章
- [XMPP]iOS聊天软件学习笔记[一]
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
- cocos2d-x 3.1.1学习笔记[23]寻找主循环 mainloop
文章出自于 http://blog.csdn.net/zhouyunxuan cocos2d到底是怎样把场景展示给我们的,我一直非常好奇. 凭个人猜想,引擎内部的结构类似于这样 while(true ...
- cocos2d-x 3.1.1 学习笔记[2]Sprite 精灵
Sprite应该是用到最多的一个类吧.无法想像一个游戏没有精灵将怎样进行愉快的玩耍. Sprite继承于Node 和 TextureProtocol. Sprite是一个2d的图像. Sprite能够 ...
- cocos2d-x 3.1.1 学习笔记[21]cocos2d-x 创建过程
文章出自于 http://blog.csdn.net/zhouyunxuan RootViewController.h #import <UIKit/UIKit.h> @interfac ...
- cocos2d-x 3.1.1 学习笔记[4]GridActions 网格动画
文章写的 http://blog.csdn.net/zhouyunxuan 老样子.见代码. //GridActions can only used on NodeGrid auto nodeGri ...
- cocos2d-x 3.1.1 学习笔记[11] http请求 + json解析
//http须要引入的头文件和命名空间 #include <network/HttpClient.h> using namespace network; //json须要引入的头文件 #i ...
- [XMPP]iOS聊天软件学习笔记[四]
昨天完成了聊天界面,基本功能算告一段落 开发时间:五天(工作时间) 开发工具:xcode6 开发平台:iOS8 XMPP框架:XMPPFramework git clone https://githu ...
- [XMPP]iOS聊天软件学习笔记[三]
今天做了好友界面,其实xmpp内部已经写好很多扩展模块,所以使用起来还是很方便的 开发时间:五天(工作时间) 开发工具:xcode6 开发平台:iOS8 XMPP框架:XMPPFramework gi ...
- [XMPP]iOS聊天软件学习笔记[二]
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
随机推荐
- PHP 关于回调的用法
class aClass { public static function directWrite($message) { echo 'this is a static function from a ...
- Scrum之Sprint物件
产品订单(Product Backlog) 一个需求的列表. 一般情况使用用户故事来表示backlog条目 理想情况每个需求项都对产品的客户或用户有价值 Backlog条目按照商业价值排列优先级 优先 ...
- VHDL之Port map and open
编SPI的master控制器,使用公司基本的元件,有些端口用不着,恰巧好二哥(不知年龄的数字组组长,本名Holger)来了,于是请教之,告曰open关键词.后来深感自己VHDL水平太水,下了一本电子书 ...
- Spring Batch的事务-Part 1:基础
原文 https://blog.codecentric.de/en/2012/03/transactions-in-spring-batch-part-1-the-basics/ This is th ...
- mysql 中时间和日期函数应用
一.MySQL 获得当前日期时间 函数 1.1 获得当前日期+时间(date + time)函数:now() mysql> select now(); +-------------------- ...
- android学习笔记---发送状态栏通知
发送消息的代码如下: //获取通知管理器 NotificationManager mNotificationManager = (NotificationManager) getSystemServi ...
- UVALive 5880 Vigenère Cipher Encryption (模拟)
Stack Machine Executor 题目链接: http://acm.hust.edu.cn/vjudge/problem/26628 Description http://7xjob4.c ...
- HD2029
Palindromes _easy version Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- 信号量的操作——semop函数
信号量的值与相应资源的使用情况有关,当它的值大于 0 时,表示当前可用的资源数的数量:当它的值小于 0 时,其绝对值表示等待使用该资源的进程个数.信号量的值仅能由 PV 操作来改变. 在 ...
- 【Android框架进阶〖0〗】ThinkAndroid注解机制
由于项目需要,开始研究ThinkAndroid. 个人认为该框架的注解机制十分新颖,所以先研究这个,顺便学习下 Java 的annotation. 粗略的看了看,该机制在BaseActivity中初始 ...