Cocos2d-x3.0TestCpp文件夹笔记(二)
3.Actions-Basic:此demo中体现ccp由Point取代
①ActionManual:直接设置精灵的属性demo。
const Color3B Color3B::RED (255, 0, 0);
const Color3B Color3B::GREEN ( 0, 255, 0);
const Color3B Color3B::BLUE ( 0, 0, 255);
//第四个參数为透明度。前三个同上
const Color4B Color4B::RED (255, 0, 0, 255);
const Color4B Color4B::GREEN ( 0, 255, 0, 255);
const Color4B Color4B::BLUE ( 0, 0, 255, 255);
//參数同上,就是用比例方式传參
const Color4F Color4F::WHITE ( 1, 1, 1, 1);
const Color4F Color4F::YELLOW ( 1, 1, 0, 1);
const Color4F Color4F::GREEN ( 0, 1, 0, 1);
const Color4F Color4F::BLUE ( 0, 0, 1, 1);
const Color4F Color4F::RED ( 1, 0, 0, 1);
const Color4F Color4F::MAGENTA( 1, 0, 1, 1);
const Color4F Color4F::BLACK ( 0, 0, 0, 1);
const Color4F Color4F::ORANGE ( 1, 0.5f, 0, 1);
const Color4F Color4F::GRAY (0.65f, 0.65f, 0.65f, 1);
//以下的求解释
const BlendFunc BlendFunc::DISABLE = {GL_ONE, GL_ZERO};
const BlendFunc BlendFunc::ALPHA_PREMULTIPLIED = {GL_ONE, GL_ONE_MINUS_SRC_ALPHA};
const BlendFunc BlendFunc::ALPHA_NON_PREMULTIPLIED = {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA};
const BlendFunc BlendFunc::ADDITIVE = {GL_SRC_ALPHA, GL_ONE};
②ActionMove:MoveTo/MoveBy。使用方法:此动作是移动。
auto actionTo = MoveTo::create(2, Point(s.width-40, s.height-40));
auto actionBy = MoveBy::create(2, Point(80,80));
auto actionByBack = actionBy->reverse();
③ActionRotate:RotateBy/RotateTo。
使用方法:此动作是旋转。
auto actionTo = RotateTo::create( 2, 45);
auto actionBy = RotateBy::create(2 , 360);
auto actionByBack = actionBy->reverse();
④ActionRotateBy3D:RotateBy。在3D世界旋转。X,Y坐标的基点是左下角。Z坐标的基点就是中心?
从源代码看出,仅仅有RotateBy有,使用方法:
auto actionBy1 = RotateBy::create(4, Vertex3F(360, 0, 0));
auto actionBy2 = RotateBy::create(4, Vertex3F(0, 360, 0));
auto actionBy3 = RotateBy::create(4 ,Vertex3F(0, 0, 360));
⑤ActionScale:ScaleTo/ScaleBy。此动作是设置缩放,參数大于零放大,小于一是缩小,负数为翻转。
使用方法:
auto actionTo = ScaleTo::create(2.0f, 0.5f);
auto actionBy = ScaleBy::create(2.0f, 1.0f, 10.0f);
auto actionBy2 = ScaleBy::create(2.0f, 5.0f, 1.0f);
⑥ActionSkew:SkewTo/SkewBy。
此动作是设置倾斜。
使用方法:(此动作不懂)
auto actionTo = SkewTo::create(2, 37.2f, -37.2f);
auto actionToBack = SkewTo::create(2, 0, 0);
auto actionBy = SkewBy::create(2, 0.0f, -90.0f);
auto actionBy2 = SkewBy::create(2, 45.0f, 45.0f);
⑦ActionRotationalSkew:相同是RotateBy/RotateTo。仅仅只是是两个參数。各自是X和Y。用单独的旋转角度。
使用方法:
auto actionByBack = actionBy->reverse();
auto actionTo = RotateTo::create(2, 180, 180);
auto actionToBack = RotateTo::create(2, 0, 0);
auto actionBy = RotateBy::create(2, 0.0f, 360);
auto actionByBack = actionBy->reverse();
auto actionBy2 = RotateBy::create(2, 360, 0);
auto actionBy2Back = actionBy2->reverse();
⑧ActionRotationalSkewVSStandardSkew:标准Skew和Rotate比較,据发现Skew会牵扯到缩放系数。
使用方法同上。
⑨ActionSkewRotateScale:三个动作同一时候运行。
SizeMake改为Size。
使用方法:
box->runAction(Sequence::create(actionTo, actionToBack, NULL));
box->runAction(Sequence::create(rotateTo, rotateToBack, NULL));
box->runAction(Sequence::create(actionScaleTo, actionScaleToBack, NULL));
⑩ActionJump:JumpTo/JumpBy。不用解释。
基本动作完毕。综上总结Skew和Rotate都为差别为。Skew改变了节点的缩放系数,详细改变求解说。
下面为特殊动作。
她们是在一个菜单里的,为Actions-Basic.
①CardinalSplineBy / CardinalSplineTo:事实上就调用了一个CardinalSplineBy。其动作运行为
四个控制点的一个矩形。
draw方法的内容MARK一下,求大神传授。
。
。
使用方法:
CCCardinalSplineBy::create(float duration, cocos2d::CCPointArray *points, float tension);
中duration是时间间隔,points是控制点列表。tension是松紧程度。tension==1时,样条线是分段直线。
tension<1向外松弛弯曲,tension>1向内缩紧弯曲。
By动作是以当前坐标为新坐标原点。
auto array = PointArray::create(20);
array->addControlPoint(Point(0, 0));
array->addControlPoint(Point(s.width/2-30, 0));
array->addControlPoint(Point(s.width/2-30, s.height-80));
array->addControlPoint(Point(0, s.height-80));
array->addControlPoint(Point(0, 0));
auto action = CardinalSplineBy::create(3, array, 0);
auto reverse = action->reverse();
auto seq = Sequence::create(action, reverse, NULL);
②CatmullRomBy / CatmullRomTo;同上一样是曲线依照控制点运动。详细的我还没有搜索到。请知道的给我说下。谢谢。
使用方法:
auto array = PointArray::create(20);
array->addControlPoint(Point(0, 0));
array->addControlPoint(Point(80, 80));
array->addControlPoint(Point(s.width - 80, 80));
array->addControlPoint(Point(s.width - 80, s.height - 80));
array->addControlPoint(Point(80, s.height - 80));
array->addControlPoint(Point(80, 80));
array->addControlPoint(Point(s.width / 2, s.height / 2));
auto action = CatmullRomBy::create(3, array);
auto reverse = action->reverse();
auto seq = Sequence::create(action, reverse, NULL);
③BezierBy / BezierTo:贝尔曲线。使用方法:
ccBezierConfig bezier;
bezier.controlPoint_1 = Point(0, s.height/2);
bezier.controlPoint_2 = Point(300, -s.height/2);
bezier.endPosition = Point(300,100);
auto bezierForward = BezierBy::create(3, bezier);
auto bezierBack = bezierForward->reverse();
auto rep = RepeatForever::create(Sequence::create( bezierForward, bezierBack, NULL));
④ActionBlink:Blink闪烁动作,使用方法:
// 持续时间
闪烁次数
static Blink* create(float duration, int blinks);
auto action1 = Blink::create(2, 10);
auto action2 = Blink::create(2, 5);
⑤ActionFade:FadeIn / FadeOut此动作为改变节点的透明度属性,当中FadeIn为全然显示,FadeOut为全然隐藏。
使用方法:
//參数为delay延时单位为秒
static FadeIn* create(float d);
auto action1 = FadeIn::create(1.0f);
auto action1Back = action1->reverse();
⑥ActionTint:TintTo / TintBy此动作为改变节点颜色属性。
使用方法:
static TintTo* create(float duration, GLubyte red, GLubyte green, GLubyte blue);
參数列表为,duration,和R,G。B。
auto action1 = TintTo::create(2, 255, 0, 255);
auto action2 = TintBy::create(2, -127, -255, -127);
auto action2Back = action2->reverse();
⑦Animation:动画demo。动画也有reverse()方法。
使用方法一:通过普通文件创建动画。
auto animation = Animation::create();
for( int i=1;i<15;i++)
{
char szName[100] = {0};
sprintf(szName, "Images/grossini_dance_%02d.png", i);
animation->addSpriteFrameWithFile(szName);
}
// should last 2.8 seconds. And there are 14 frames.
animation->setDelayPerUnit(2.8f / 14.0f);
animation->setRestoreOriginalFrame(true);
auto action = Animate::create(animation);
_grossini->runAction(Sequence::create(action, action->reverse(), NULL));
使用方法二:通过plist创建动画
auto cache = AnimationCache::getInstance();
cache->addAnimationsWithFile("animations/animations-2.plist");
auto animation2 = cache->getAnimation("dance_1");
auto action2 = Animate::create(animation2);
_tamara->runAction(Sequence::create(action2, action2->reverse(), NULL));
注意:animations-2.plist文件和其它plist文件不一样。
⑧⑨Sequence: Move + Rotate:顺序运行n个动作。
使用方法:
static Sequence* create(FiniteTimeAction *action1, ...) CC_REQUIRES_NULL_TERMINATION;
//參数以NULL结尾。
⑩问题 CallFunc中的create方法的调用 參数不同,调用的是不是相应的CalkFunc家族的类。
auto action = Sequence::create(
Place::create(Point(200,200)),
Show::create(),
MoveBy::create(1, Point(100,0)),
CallFunc::create( CC_CALLBACK_0(ActionSequence2::callback1,this)),
CallFunc::create( CC_CALLBACK_0(ActionSequence2::callback2,this,_grossini)),
CallFunc::create( CC_CALLBACK_0(ActionSequence2::callback3,this,_grossini,0xbebabeba)),
NULL);
(11)"Sequence: Move + Rotate + Scale + RemoveSelf":移除自己动作,使用方法:
static RemoveSelf * create(bool isNeedCleanUp = true);
auto action = Sequence::create(
MoveBy::create( 2, Point(240,0)),
RotateBy::create( 2, 540),
ScaleTo::create(1,0.1f),
RemoveSelf::create(),
NULL);
(12)Spawn: Jump + Rotate:函数为:ActionSpawn:几个动作同一时候运行。
使用方法:
auto action = Spawn::create(
JumpBy::create(2, Point(300,0), 50, 4),
RotateBy::create( 2, 720),
NULL);
(13)Reverse an action:函数为:ActionReverse,动作的恢复。
使用方法:
auto jump = JumpBy::create(2, Point(300,0), 50, 4);
auto action = Sequence::create( jump, jump->reverse(), NULL);
(14)DelayTime: m + delay + m:函数为:ActionDelayTime,延时动作。
使用方法:
auto move = MoveBy::create(1, Point(150,0));
//延时动作的參数单位为秒
auto action = Sequence::create( move, DelayTime::create(2), move, NULL);
(15)Repeat / RepeatForever actions:函数为:ActionRepeat:
使用方法:
//反复三次指定动作。当中Place动作是放置节点到指定位置,就是把setPosition弄成了动作。
//当中最后的參数“3”就是反复次数
auto action1 = Repeat::create(Sequence::create( Place::create(Point(60,60)), a1, NULL) , 3);
//无休止的反复指定动作。
auto action2 = RepeatForever::create(Sequence::create(a1->clone(), a1->reverse(), NULL));
(16)CallFuncN + RepeatForever:函数为:ActionRepeatForever。通过回调函数使节点无休止运行指定动作。
使用方法:
auto action = Sequence::create(DelayTime::create(1),
CallFunc::create( std::bind( &ActionRepeatForever::repeatForever, this, _grossini) ),
NULL);
void ActionRepeatForever::repeatForever(Node* sender)
{
auto repeat = RepeatForever::create( RotateBy::create(1.0f, 360) );
sender->runAction(repeat);
}
(17)Repeat/RepeatForever + RotateTo:函数为: ActionRotateToRepeat 。疑问,为什么当精灵_kathia运行完动作后会旋转90°,个人感觉是bug。
还有就是“clone()方法”的使用方法。
使用方法:
auto act1 = RotateTo::create(1, 90);
auto act2 = RotateTo::create(1, 0);
auto seq = Sequence::create(act1, act2, NULL);
auto rep1 = RepeatForever::create(seq);
auto rep2 = Repeat::create( seq->clone(), 10);
(18)RepeatForever / Repeat + Rotate:函数为:ActionRotateJerk。同上 仅仅是角度不同。
(19)Callbacks: CallFunc with std::function():函数为: ActionCallFunction 。解说各种方式创建CallFunc系列动作(多态创建)。
源代码:疑点。參数this的作用,调用的是哪个create函数。
auto action1 = Sequence::create(
MoveBy::create(2, Point(200,0)),
CallFunc::create( std::bind(&ActionCallFunction::callback1, this) ),
CallFunc::create(
// lambda 表达式
[&](){
auto s = Director::getInstance()->getWinSize();
auto label = Label::createWithTTF("called:lambda callback", "fonts/Marker Felt.ttf", 16.0f);
label->setPosition(Point( s.width/4*1,s.height/2-40));
this->addChild(label);
} ),
NULL);
auto action2 = Sequence::create(
ScaleBy::create(2 , 2),
FadeOut::create(2),
CallFunc::create( std::bind(&ActionCallFunction::callback2, this, _tamara) ),
NULL);
auto action3 = Sequence::create(
RotateBy::create(3 , 360),
FadeOut::create(2),
CallFunc::create( std::bind(&ActionCallFunction::callback3, this, _kathia, 42) ),
NULL);
void ActionCallFunction::callback1();
void ActionCallFunction::callback2(Node* sender);
void ActionCallFunction::callback3(Node* sender, long data);
(20)Grossini should jump after moving:函数为: ActionCallFuncN 。须要重看。
源代码:
auto action = Sequence::create(
MoveBy::create(2.0f, Point(150,0)),
CallFuncN::create( CC_CALLBACK_1(ActionCallFuncN::callback, this)),
//假设用CallFuncN创建CallFuncN系列的回调函数。则不须要传递Node*參数。(?)
NULL);
_grossini->runAction(action);
void ActionCallFuncN::callback(Node* sender )
{
auto a = JumpBy::create(5, Point(0,0), 100, 5);
sender->runAction(a);
}
(21)simulates CallFuncND with std::bind():函数为:ActionCallFuncND:移动后自己主动消失。
源代码:
auto action = Sequence::create(
MoveBy::create(2.0f, Point(200,0)),
CallFuncN::create( CC_CALLBACK_1(ActionCallFuncND::doRemoveFromParentAndCleanup, this, true)),
//用CallFuncN的方法创建动作。回调函数还能带有和传其它參数?
NULL);
_grossini->runAction(action);
void ActionCallFuncND::doRemoveFromParentAndCleanup(Node* sender, bool cleanup)
{
_grossini->removeFromParentAndCleanup(cleanup);
}
CallFunc系列总结:能够用CallFunc::create()方法创建这个系列的回调函数,仅仅要參数不同就可以。第二个參数固定为this,意识是这个函数的
调用者。使用方法例如以下所看到的:
CallFunc::create( CC_CALLBACK_0(ActionSequence2::callback1,this)),
CallFunc::create( CC_CALLBACK_0(ActionSequence2::callback2,this,_grossini)),
CallFunc::create( CC_CALLBACK_0(ActionSequence2::callback3,this,_grossini,0xbebabeba)),
如有错误,希望大家多多指正。谢谢。
Cocos2d-x3.0TestCpp文件夹笔记(二)的更多相关文章
- c头文件包含关系--记今天调试的郁闷经历
c头文件包含关系--记今天调试的郁闷经历 彭会锋 2016-08-05 21:54:08 c头文件的包含
- ansible笔记(5):常用模块之文件操作(二)
ansible笔记():常用模块之文件操作(二) 文件操作类模块 find模块 find模块可以帮助我们在远程主机中查找符合条件的文件,就像find命令一样. 此处我们介绍一些find模块的常用参数, ...
- linux内核中链表代码分析---list.h头文件分析(二)【转】
转自:http://blog.chinaunix.net/uid-30254565-id-5637598.html linux内核中链表代码分析---list.h头文件分析(二) 16年2月28日16 ...
- 计算机文件基本上分为二种:二进制文件和 ASCII(也称纯文本文件)
文本文件是可以看到的字符, 二进制文件是不可视字符,如图片. 二进制文件: 包含在 ASCII及扩展 ASCII 字符中编写的数据或程序指令的文件.计算机文件基本上分为二种:二进制文件和 ASCII( ...
- Linux更改文件权限(二)
更改文件权限(二)============================== (参考于千锋教育教学笔记) 命令umask [root@aminglinux ~]# umask 0022 [root@ ...
- linux内核中的文件描述符(二)--socket和文件描述符
http://blog.csdn.net/ce123_zhouwei/article/details/8459730 Linux内核中的文件描述符(二)--socket和文件描述符 Kernel ve ...
- 文件上传二:FormData上传
介绍三种上传方式: 文件上传一:伪刷新上传 文件上传二:FormData上传 文件上传三:base64编码上传 Flash的方式也玩过,现在不推荐用了. 真正的异步上传,FormData的更多操作,请 ...
- OpenCV读写视频文件解析(二)
OpenCV读写视频文件解析(二) VideoCapture::set 设置视频捕获中的属性. C++:bool VideoCapture::set(int propId, double value) ...
- python04篇 文件操作(二)、集合
一.文件操作(二) 1.1 利用with来打开文件 # with open ,python 会自动关闭文件 with open('a.txt', encoding='utf-8') as f: # f ...
随机推荐
- 30年的Hello world
30 年的 Hello world 转载自:http://www.admin10000.com/document/2398.html 最近我在7月4日这一天所在的那周休假了.休假期间,我利用大把的时间 ...
- C# 两个获得程序运行路径的函数
EXE文件的存储路径,不太受调用时环境变量的影响: Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Lo ...
- python中 __name__及__main()__的使用
python中 __name__及__main()__的使用 #hello.py def sayHello(): str="hello" print(str); if __name ...
- bzoj2705
一个常用的结论(方法) 只要知道gcd(i,n)=L 的i的个数s,我们就能很轻易得出答案 gcd(i,n)=L gcd(i/L,n/L)=1 不难得到这样的s=与n/L互质的个数=phi(n/L) ...
- POJ_3104_Drying_(二分,最小化最大值)
描述 http://poj.org/problem?id=3104 n件衣服,第i件衣服里面有水a[i],自然风干每分钟干1个水,用吹风机每分钟干k个水,但是同时只能对一件衣服使用吹风机,求干完所有衣 ...
- BZOJ3522: [Poi2014]Hotel
3522: [Poi2014]Hotel Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 195 Solved: 85[Submit][Status] ...
- win7怎么调屏幕自动休眠时间
win7怎么调屏幕自动休眠时间 2013-03-28 17:13匿名 | 分类:Windows | 浏览1327次 我也不知道怎么说 我的电脑的问题就是 电脑放那不动过2,3分钟屏幕就暗了 要是不动过 ...
- 将access数据转换成oracle数据
1.打开access数据文件,选择需转换的表/导出/ODBC数据库 2.输入导出的表名 3.选择数据源,点击新建 4.选择数据源驱动程序 5.保存DSN文件 6.下一步,输入oracle的SERVIC ...
- cssText设置css样式
js中用cssText设置css样式 (2012-08-21 10:40:22) 转载▼ 标签: js 如果网页中一个 id为“no”的标签,暂且当div标签来tell:想要在js中设置这个div ...
- [LeetCode] 3Sum 解题思路
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all un ...