常见变换
MoveTo/MoveBy:位置变换(移动到某个位置/移动某个偏移量)
RotateTo/RotataBy角度变换
RotateTo::create(2, 61.0f);
RotateTo::create(2, 180, 180); // ActionRotationalSkew
RotateBy::create(4, Vec3(360, 0, 0));传入一个三维向量 //ActionRotateBy3D
ScaleTo/ScaleBy缩放变换
SkewTo/SkewBy(dt,sx,sy)偏度变换
sx,sy分别 x轴,y轴的偏移角度。
JumpTo/JumpBy 跳跃(float duration, const Vec2& position, float height, int jumps) 时间,位置偏移,高度,次数
CardinalSplineBy duration,array,tension tension表示松弛程度
球面坐标
下面是代码,部分参考http://bbs.9ria.com/thread-199302-1-1.html
Size visbleSize=Director::getInstance()->getVisibleSize();
auto sprite=Sprite::create("hero.png");
sprite->setPosition(visbleSize.width/2,visbleSize.height/2);
this->addChild(sprite);
//DelayTime延时几秒
//参数1:延时的时间
DelayTime* delayAction=DelayTime::create(2);
MoveTo/MoveBy 创建一个移动动作
参数1:移动所需时间 参数2:移动到的位置
//auto moveTo=MoveTo::create(2,Vec2(visbleSize.width/4,visbleSize.height/4));
//sprite->runAction(moveTo);
RotateTo/RotateBy 创建一个角度变换动作(旋转中心在锚点)
参数1::角度变换所需要的时间 参数2(float):变换的角度
//auto rotateTo=RotateTo::create(2,90);
//sprite->runAction(rotateTo);
RotateTo/RotateBy 创建一个角度变换动作(旋转中心在锚点所在的x,y轴)
参数1::角度变换所需要的时间 参数2,参数3(float):沿x,y轴旋转的角度
//auto rotateTo=RotateTo::create(2,0,180); //翻转图片180
//sprite->runAction(rotateTo);
RotateBy in 3D 创建一个角度变换动作 (3D)
参数1::角度变换所需要的时间 参数2,参数3,参数4(float):沿x,y,z轴旋转的角度
//auto rotateBy3D=RotateBy::create(2,Vec3(0,0,90));
//sprite->runAction(rotateBy3D);
ScaleTo/ScaleBy 创建一个缩放变换动作
参数1::缩放变换所需要的时间 参数2,参数3(float):缩放的倍数
//auto scaleTo=ScaleTo::create(2,1,2);
//sprite->runAction(scaleTo);
//return true;
SkewTo/SkewBy 创建一个倾斜变换动作
参数1::倾斜变换所需要的时间 参数2,参数3(float):x,y轴向z轴倾斜的角度
//auto skewTo=SkewBy::create(2,0,45);
//sprite->runAction(skewTo);
//return true;
JumpTo/JumpBy 创建一个跳跃动作
参数1::跳跃所需要的时间 参数2:跳跃到的位置 参数3:跳跃的高度 参数4:跳跃次数
//auto jumpTo=JumpTo::create(2,ccp(400,300),80,3);
//sprite->runAction(jumpTo);
//return true;
BezierTo 创建一个贝塞尔曲线运动动作
ccBezierConfig结构体
// ccBezierConfig bezier;
设置bezier的三个关键点
//sprite->setPosition(0,0);
//bezier.controlPoint_1=Vec2(0,0);
//bezier.controlPoint_2=Vec2(100,200);
//bezier.endPosition=Vec2(400,300);
//
创建Bezier运动
参数1:运动所需要的时间 参数2:ccBezierConfig结构体
//auto bezierTo=BezierTo::create(3,bezier);
//sprite->runAction(bezierTo);
FadeIn/FadeOut 渐变出现/渐变消失
参数1:渐变时间
//auto fadeIn=FadeIn::create(2);
//auto fadeOut=FadeOut::create(2);
//auto seqAction=Sequence::create(fadeOut,DelayTime::create(2),fadeIn,NULL);
//sprite->runAction(seqAction);
TintTo 创建一个色彩变化到目标颜色的动作,不支持reverse()方法
参数1::所需要的时间 参数2,3,4:渐变的颜色值
//auto tintTo=TintTo::create(2,255,255,0);
//sprite->runAction(tintTo);
//return true;
TintTo 创建目标颜色消失的动作,支持reverse()方法
参数1::所需要的时间 参数2,3,4:渐变的颜色值
//auto tintBy=TintBy::create(2,255,255,0);
//sprite->runAction(tintBy);
Blink 创建一个闪烁的动作
参数1::所需要的时间 参数2:闪烁次数
//auto blink=Blink::create(2,4);
//sprite->runAction(blink);
// //OrbitCamera
// //作用:创建一个球面坐标轨迹进行旋转的动作
// //参数1 : 旋转轨迹的时间
// //参数2 :起始半径
// //参数3:半径差
// //参数4:起始z角(z轴与y轴所成的角) 图中θ
// //参数5:旋转z角的差
// //参数6:起始x角(x轴与y轴所成的角) 图中φ
// //参数7:旋转x角的差
//ActionInterval * orbitcamera = OrbitCamera::create(3, 10, 0, 45, 180, 90, 0);
//sprite->runAction(orbitcamera);
// CardinalSpline
// 作用:创建数组 点的数组
PointArray * array = PointArray::create(20);
array->addControlPoint(ccp(0,0));
array->addControlPoint(ccp(210,0));
array->addControlPoint(ccp(210,240));
array->addControlPoint(ccp(0,160));
array->addControlPoint(ccp(0,0));
CardinalSplineTo/CardinalSplineBy
作用:创建一个样条曲线轨迹的动作
参数1:完成轨迹所需的时间
参数2:控制点的坐标数组
拟合度 其值= 0 路径最柔和
//auto cardinalSplineTo=CardinalSplineTo::create(3, array, 0);
//sprite->runAction(cardinalSplineTo);
CatmullRomTo CatmullRomBY
作用:创建一个样条插值轨迹
参数1:完成轨迹的时间
参数2:控制点的数组坐标
//ActionInterval * catmullRomTo = CatmullRomTo::create(3, array);
//sprite->runAction(catmullRomTo);
Follow
作用:创建一个跟随动作
参数1:跟随的目标对象
跟随范围,离开范围就不再跟随,用于层跟踪英雄镜头
创建一个参照物ref
mark一下 还是不太清楚第二个参数Rect的作用
//auto ref=Sprite::create("ref.png");
//this->addChild(ref);
//ref->setPosition(visbleSize.width/2+20,visbleSize.height/2);
//sprite->runAction(MoveBy::create(6,Vec2(400,0)));
//auto follow=Follow::create(sprite,Rect(0,0,700,160));
//this->runAction(follow);
// EaseBounceIn
// 目标动作
// ActionInterval* move = MoveTo::create(3, ccp(300, sprite->getPositionY()));
让目标动作缓慢开始
参数:目标动作
// ActionInterval * EaseBounceIn = EaseBounceIn::create(move);
// sprite->runAction(EaseBounceIn);
//EaseBounceOut
// 作用:让目标动作赋予反弹力,且以目标动作结束位子开始反弹
// 参数目标动作
// ActionInterval * easeBounceOut = EaseBounceOut ::create(move);
// sprite->runAction(easeBounceOut);
// EaseBounceInOut
// 作用:让目标动作赋予反弹力,且以目标动作起始与结束位子开始反弹
// ActionInterval * easeBounceInOut= EaseBounceInOut::create(move);
// sprite->runAction(easeBounceInOut);
// EaseBackIn
// 作用:让目标动作赋予回力 , 且以目标动作起点位置作为回力点
// 参数:目标动作
// ActionInterval * easeBackIn = EaseBackIn::create(move);
// sprite->runAction(easeBackIn);
// EaseBackOut
// 作用:让目标动作赋予回力 , 且以目标动作终点位置作为回力点
// 参数:目标动作
// ActionInterval *easeBackOut = EaseBackOut::create(move);
// sprite->runAction(easeBackOut);
// EaseBackInOut
// 作用:让目标动作赋予回力 , 且以目标动作起点和终点位置作为回力点
// 参数:目标动作
// ActionInterval * easeBackInOut = EaseBackInOut::create(move);
// sprite->runAction(easeBackInOut);
// EaseElasticIn
// 作用:让目标动作赋予弹性 ,且以目标动作起点位子赋予弹性
// 参数:目标动作
// ActionInterval * easeElasticIn= EaseElasticIn::create(move);
// sprite->runAction(easeElasticIn);
// EaseElasticOut
// 作用:让目标动作赋予弹性 ,且以目标动作终点位子赋予弹性
// 参数:目标动作
// ActionInterval *easeElasticOut = EaseElasticOut::create(move);
// sprite->runAction(easeElasticOut);
// EaseElasticInOut
// 作用:让目标动作赋予弹性 ,且以目标动作起点和终点位子赋予弹性
// 参数:目标动作
// ActionInterval *easeElasticInOut = EaseElasticOut::create(move);
// sprite->runAction(easeElasticInOut);
// EaseExponentialIn
// 让目标动作缓慢开始
// 参数:目标动作
// ActionInterval * easeExponentialIn= EaseExponentialIn::create(move);
// sprite->runAction(easeExponentialIn);
// EaseExponentialOut
// 让目标动作缓慢中止
// 参数:目标动作
// ActionInterval * easeExponentialIn= EaseExponentialOut::create(move);
// sprite->runAction(easeExponentialIn);
// EaseExponentialInOut
// 让目标动作缓慢开始和中止
// 参数:目标动作
// ActionInterval * easeExponentialInOut= EaseExponentialInOut::create(move);
// sprite->runAction(easeExponentialInOut);
// EaseRateAction
// 作用 : 让目标动作设置速率
// 参数1:目标动作
// 参数2:速率
// ActionInterval * move = MoveTo::create(5, ccp(300,sprite->getPositionY()));
// ActionInterval * easeRateAction = EaseRateAction::create(move, 3);
// sprite->runAction(easeRateAction);
// EaseSineIn
// 作用:动作由慢到快
// 参数:目标动作
// ActionInterval * easeSineIn = EaseSineIn::create(move);
// sprite->runAction(easeSineIn);
// EaseSineOut
// 作用:动作由快到慢
// 参数:目标动作
// ActionInterval * easeSineOut = EaseSineOut::create(move);
// sprite->runAction(easeSineOut);
// EaseSineInOut
// 作用:动作由慢到快再快到慢
// 参数:目标动作
// ActionInterval * easeSineInOut = EaseSineInOut::create(move);
// sprite->runAction(easeSineInOut);
// Speed
// 作用:让目标动作运行速度加倍
// 参数1:目标动作
// 参数2:倍速
// ActionInterval * move = MoveTo::create(10, ccp(300,sprite->getPositionY()));
// Speed * speed =Speed::create(move, 100);
// sprite->runAction(speed);
// Spawn
// 作用:让多个动作同时执行
// 参数:目标动作的可变参数
// ActionInterval * move = MoveTo::create(10, ccp(300,sprite->getPositionY()));
// ActionInterval * scale = ScaleTo::create(2, 3);
// ActionInterval * rotate = RotateTo::create(4, 190);
// FiniteTimeAction * spawn =Spawn::create(move,scale,rotate,NULL);
// sprite->runAction(spawn);
// Sequence
// 作用:让多个动作按照前后顺序逐一执行
// 参数:目标动作的可变参数
// ActionInterval * move = MoveTo::create(2, ccp(300, sprite->getPositionY()));
// ActionInterval * scale = ScaleTo::create(2, 3);
// FiniteTimeAction * seq= Sequence::create(move,scale,NULL);
// sprite->runAction(seq);
// 扩展如果要对目标动作全部进行方向运动,可以使用如下形式操作
// FiniteTimeAction *seq=Sequence::create(moveby,scaleby,...NULL);
// FiniteTimeAction * reverseseq = Sequence::create(seq,seq->reverse(),NULL)
// 注意Sequence中的所有动作都必须支持reverse函数,否则会出现异常
// ActionInterval * move = MoveBy::create(2, ccp(300, sprite->getPositionY()));
// ActionInterval * scale = ScaleBy::create(2, 3);
// FiniteTimeAction * seq= Sequence::create(move,scale,NULL);
// FiniteTimeAction * reveseseq = Sequence::create(seq,seq->reverse(),NULL);
// sprite->runAction(reveseseq);
// Repeat
// 作用:对目标动作进行重复运动(目标动作可以是Sequence ,Spawn)
// 参数1:目标动作
// 参数2:重复次数
// ActionInterval * move = MoveTo::create(2, ccp(300, sprite->getPositionY()));
// ActionInterval * move2 = MoveTo::create(2, ccp(100,100));
// FiniteTimeAction*seq =Sequence::create(move,move2,NULL);
// FiniteTimeAction *repeat = Repeat::create(seq, 3);
// sprite->runAction(repeat);
// RepeatForever
// 作用:对目标动作进行永久性的重复运动(目标动作可以是Sequence ,Spawn)
// 参数:目标动作
// ActionInterval * move = MoveTo::create(1, ccp(300, sprite->getPositionY()));
// ActionInterval * move1 = MoveTo::create(1, ccp(100,100));
// FiniteTimeAction* seq = Sequence::create(move,move1,NULL);
// ActionInterval * repeatForever =RepeatForever::create((ActionInterval* )seq);
// sprite->runAction(repeatForever);
// CallFunc
// 作用:创建一个回调动作(调用不带参数的回调方法);
// 参数1:目标动作
// 参数2:目标回调函数
// ActionInterval * move = MoveTo::create(1, ccp(300, sprite->getPositionY()));
// CallFunc * funcall= CallFunc::create(this, callfunc_selector(HelloWorld::callbackC));
// FiniteTimeAction * seq = Sequence::create(move,funcall,NULL);
// sprite->runAction(seq);
// CallFuncN
// 作用:创建一个回调动作(调用 带一个参数的回调方法);
// 参数1:目标动作
// 参数2:目标回调函数
// ActionInterval * move = MoveTo::create(1, ccp(300, sprite->getPositionY()));
// CallFuncN * funcall= CallFuncN::create(this, callfuncN_selector(HelloWorld::callbackN));
// FiniteTimeAction * seq = Sequence::create(move,funcall,NULL);
// sprite->runAction(seq);
CallFuncND
作用:创建一个回调动作(调用 带两个参数的回调方法);
参数1:目标动作
参数2:目标回调函数
//ActionInterval * move = MoveTo::create(1, ccp(300, sprite->getPositionY()));
//CallFuncND * funcall= CallFuncND::create(this, callfuncND_selector(HelloWorld::callbackND) ,(void*)0xbebabeba);
//FiniteTimeAction * seq = Sequence::create(move,funcall,NULL);