Cocos2d-x   发布时间:2022-05-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Cocos2d-x 3.x中43种常用动作汇总大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

本文总结Cocos2d-x 3.x版本中43种常用动作类,包括每个类的作用、使用方法以及所实现的效果。


ScaleBy

  • 作用: 创建一个缩放的动作

  • 参数1:达到缩放大小的所需时间

  • 参数2:缩放比例

1
2
3
ActionInterval*scaleby=ScaleBy::create(2,2);
ActionInterval*actionbyBACk=scaleby->reverse();
sp->runAction(actionbyBACk);

RotateTo

  • 作用:创建一个旋转的动作

  • 参数1:旋转的时间

  • 参数2:旋转饿角度 0 - 360

2
ActionInterval*rotateto=RotateTo::create(2,90);
sp->runAction(rotateto);

SkewTo

  • 作用:创建一个倾斜的动作

  • 参数1:倾斜到特定角度所需的时间

  • 参数2:x轴的倾斜角度

  • 参数3:y轴的倾斜角度

ActionInterval*skewto=SkewTo::create(2,10,10);
sp->runAction(skewto);


JumpTo

  • 作用:创建一个跳的动作

  • 参数1:跳到目标动作位子的所需时间

  • 参数2:目标位置

  • 参数3:跳的高度

  • 参数4:跳到目标位置的次数

ActionInterval*jumpto=JumpTo::create(2,ccp(300,200),50,4);
sp->runAction(jumpto);

JumpBy

  • 作用:创建一个跳的动作

  • 参数1:跳到目标动作位子的所需时间

  • 参数2:目标位置

  • 参数3:跳的高度

  • 参数4:跳到目标位置的次数

这个支持方向动作reverse

ActionInterval*jumpby=JumpBy::create(3,4);
ActionInterval*ac=jumpby->reverse();
sp->runAction(ac);


@H_82_262@Bezier

ccBezierConfig结构体

3
4
ccBezierConfigbezierCon;
bezierCon.controlPoint_1=PointMake(200,150); //控制点1
bezierCon.controlPoint_2=PointMake(200,160); //控制点2
bezierCon.endPosition=PointMake(340,100); //结束位置

BezierTo

  • 创建一个贝塞尔曲线运动的动作

  • 参数1:贝塞尔曲线运动的时间

  • 参数2 :ccBezierConfig结构体

ActionInterval*action=BezierTo::create(2,bezierCon);
ActionInterval*action=BezierBy::create(3,bezierCon); //支持反向
ActionInterval*action1=action->reverse();
sp->runAction(action1);

FadeIn

  • 作用:创建一个渐变出现的动作

  • 参数是时间

ActionInterval*fadein=FadeIn::create(2);
sp->runAction(fadein);

FadeOut

  • 作用:创建一个渐变消失的动作

  • 参数是时间

ActionInterval*fadeout=FadeOut::create(2);
sp->runAction(fadeout);

TintTo

  • 作用:创建一个色彩变化的消失动作

  • 参数1:色彩变化的动作

  • 参数2 :红色分量

  • 参数3:蓝色分量

ActionInterval*Tinto=TintTo::create(3,255,0);
sp->runAction(Tinto);

TintBy

  • 作用:创建一个色彩变化的出现动作

  • 参数1:色彩变化的动作

  • 参数2:红色分量

  • 参数3:蓝色分量,但是加了reverse就是反向的

ActionInterval*Tintby=TintBy::create(3,255);
ActionInterval*Tintby1=Tintby->reverse();
sp->runAction(Tintby1);

Blink

  • 作用:创建一额闪烁的动作

  • 参数1:闪烁完成的时间

  • 参数2:闪烁的次数

ActionInterval*blink=Blink::create(3,monospace!important; font-size:1em!important; min-height:inherit!important; BACkground:none!important">sp->runAction(blink);


DelayTime

  • 作用:创建一个延迟的动作

  • 参数:延迟的时间

ActionInterval*delaytime=DelayTime::create(3);
sp->runAction(delaytimE);

OrbitCamera

  • 作用:创建一个球面坐标轨迹进行旋转的动作

  • 参数1: 旋转轨迹的时间

  • 参数2:起始半径

  • 参数3:半径差

  • 参数4:起始z角

  • 参数5:旋转z角的差

  • 参数6:起始x角

  • 参数7:旋转x角的差

@H_319_607@ 2
ActionInterval*orbitcamera=OrbitCamera::create(3,45,180,90,monospace!important; font-size:1em!important; min-height:inherit!important; BACkground:none!important">sp->runAction(orbitcamera);

CardinalSpline

4
5
6
PointArray*array=PointArray::create(@R_262_10464@
array->addControlPoint(ccp(0,0));
array->addControlPoint(ccp(210,0));
:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,240));
:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,160));
:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,0));

CardinalSplineTo

2
ActionInterval*CardinalSplineTo=CardinalSplineTo::create(3,array,monospace!important; font-size:1em!important; min-height:inherit!important; BACkground:none!important">sp->runAction(CardinalSplineTo);

CardinalSplineBy

2
ActionInterval*CardinalSplineBy=CardinalSplineBy::create(3,monospace!important; font-size:1em!important; min-height:inherit!important; BACkground:none!important">sp->runAction(CardinalSplineBy);

CatmullRomTo、CatmullRomBY

ActionInterval*catmullRomTo=CatmullRomTo::create(3,array);
sp->runAction(catmullRomTo);

Follow

创建一个参照物spT

6
7
Sprite*spt=Sprite::create( "Icon.png" );
spt->setPosition(ccp(420,40));
addChild(spt);
sp->runAction(MoveTo::create(3,ccp(940,sp->getPositionY())));
Follow*follow=Follow::create(sp,RectMake(0,960,320));
this ->runAction(follow);

EaseBounceIn

目标动作

1
ActionInterval*move=MoveTo::create(3,sp->getPositionY()));

让目标动作缓慢开始

参数:目标动作

ActionInterval*EaseBounceIn=EaseBounceIn::create(movE);
sp->runAction(EaseBounceIn);

EaseBounceOut

ActionInterval*easeBounceOut=EaseBounceOut::create(movE);
sp->runAction(easeBounceOut);

EaseBounceInOut

ActionInterval*easeBounceInOut=EaseBounceInOut::create(movE);
sp->runAction(easeBounceInOut);

EaseBACkIn

ActionInterval*easeBACkIn=EaseBACkIn::create(movE);
sp->runAction(easeBACkIn);

EaseBACkOut

ActionInterval*easeBACkOut=EaseBACkOut::create(movE);
sp->runAction(easeBACkOut);

EaseBACkInOut

ActionInterval*easeBACkInOut=EaseBACkInOut::create(movE);
sp->runAction(easeBACkInOut);

EaseElasticIn

ActionInterval*easeElasticIn=EaseElasticIn::create(movE);
sp->runAction(easeElasticIn);

EaseElasticOut

ActionInterval*easeElasticOut=EaseElasticOut::create(movE);
sp->runAction(easeElasticOut);

EaseElasticInOut

ActionInterval *easeElasticInOut = EaseElasticOut::create(movE);

sp->runAction(easeElasticInOut);

EaseExponentialIn

ActionInterval*easeExponentialIn=EaseExponentialIn::create(movE);
sp->runAction(easeExponentialIn);

EaseExponentialOut

2
ActionInterval*easeExponentialIn=EaseExponentialOut::create(movE);
EaseExponentialInOut

  • 作用:让目标动作缓慢开始和中止

  • 参数:目标动作

ActionInterval*easeExponentialInOut=EaseExponentialInOut::create(movE);
sp->runAction(easeExponentialInOut);

EaseRateAction

  • 作用:让目标动作设置速率

  • 参数1:目标动作

  • 参数2:速率

3
ActionInterval*move=MoveTo::create(5,sp->getPositionY()));
ActionInterval*easeRateAction=EaseRateAction::create(move,3);
sp->runAction(easeRateAction);

EaseSineIn

  • 作用:动作由慢到快

  • 参数:目标动作

ActionInterval*easeSineIn=EaseSineIn::create(movE);
sp->runAction(easeSineIn);

EaseSineOut

  • 作用:动作由快到慢

  • 参数:目标动作

ActionInterval*easeSineOut=EaseSineOut::create(movE);
sp->runAction(easeSineOut);

EaseSineInOut

  • 作用:动作由慢到快再快到慢

  • 参数:目标动作

ActionInterval*easeSineInOut=EaseSineInOut::create(movE);
sp->runAction(easeSineInOut);

Speed

  • 作用:让目标动作运行速度加倍

  • 参数1:目标动作

  • 参数2:倍速

3
ActionInterval*move=MoveTo::create(10,monospace!important; font-size:1em!important; min-height:inherit!important; BACkground:none!important">Speed*speed=Speed::create(move,100);
sp->runAction(speed);

Spawn

  • 作用:让多个动作同时执行

  • 参数:目标动作的可变参数

5
ActionInterval*scale=ScaleTo::create(2,monospace!important; font-size:1em!important; min-height:inherit!important; BACkground:none!important">ActionInterval*rotate=RotateTo::create(4,190);
FiniteTimeAction*spawn=Spawn::create(move,scale,rotate,null);
sp->runAction(spawn);

Sequence

  • 作用:让多个动作按照前后顺序逐一执行

  • 参数:目标动作的可变参数

4
ActionInterval*move=MoveTo::create(2,monospace!important; font-size:1em!important; min-height:inherit!important; BACkground:none!important">FiniteTimeAction*seq=Sequence::create(move,null);
sp->runAction(seq);

扩展如果要对目标动作全部进行方向运动,可以使用如下形式操作

2
FiniteTimeAction*seq=Sequence::create(moveby,scaleby,...null);
FiniteTimeAction*reverseseq=Sequence::create(seq,seq->reverse(),NULL)

注意Sequence中的所有动作都必须支持reverse函数,否则会出现异常

5
ActionInterval*move=MoveBy::create(2,monospace!important; font-size:1em!important; min-height:inherit!important; BACkground:none!important">ActionInterval*scale=ScaleBy::create(2,monospace!important; font-size:1em!important; min-height:inherit!important; BACkground:none!important">FiniteTimeAction*reveseseq=Sequence::create(seq,monospace!important; font-size:1em!important; min-height:inherit!important; BACkground:none!important">sp->runAction(reveseseq);

Repeat

  • 作用:对目标动作进行重复运动(目标动作可以是Sequence ,Spawn)

  • 参数1:目标动作

  • 参数2:重复次数

ActionInterval*move2=MoveTo::create(2,ccp(100,100));
FiniteTimeAction*repeat=Repeat::create(seq,3);
sp->runAction(repeat);

RepeatForever

  • 作用:对目标动作进行永久性的重复运动(目标动作可以是Sequence ,Spawn)

  • 参数:目标动作

@H_319_607@ 5
ActionInterval*move=MoveTo::create(1,monospace!important; font-size:1em!important; min-height:inherit!important; BACkground:none!important">ActionInterval*move1=MoveTo::create(1,move1,monospace!important; font-size:1em!important; min-height:inherit!important; BACkground:none!important">ActionInterval*repeatForever=RepeatForever::create((ActionInterval*)seq);
sp->runAction(repeatForever);

CallFunc

4
CallFunc*funcall=CallFunc::create( ,callfunc_SELEctor(HelloWorld::callBACkC));
CallFuncN

  • 作用:创建一个回调动作(调用带一个参数的回调方法);

  • 参数1:目标动作

  • 参数2:目标回调函数

ActionInterval * move = MoveTo::create(1,sp->getPositionY()));

CallFuncN * funcall= CallFuncN::create(this,callfuncN_SELEctor(HelloWorld::callBACkN));

FiniteTimeAction * seq = Sequence::create(move,null);

sp->runAction(seq);

CallFuncND

  • 作用:创建一个回调动作(调用 带两个参数的回调方法);

  • 参数1:目标动作

  • 参数2:目标回调函数

5
CallFuncND*funcall=CallFuncND::create( :1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,callfuncND_SELEctor(HelloWorld::callBACkND),( void *)0xbebabeba);
sp->runAction(seq);
return true ;

@H_123_1675@来源网址:http://www.sundaboke.com/?post=34

大佬总结

以上是大佬教程为你收集整理的Cocos2d-x 3.x中43种常用动作汇总全部内容,希望文章能够帮你解决Cocos2d-x 3.x中43种常用动作汇总所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。