Home >Database >Mysql Tutorial >Cocos2d-x学习笔记(15)(Action动作)

Cocos2d-x学习笔记(15)(Action动作)

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 15:01:141344browse

Cocos2d-x提供的动作,只要是CCNode对象都可以使用。 1、常用操作如下: 1)runAction(cocos2d::CCAction* action)//执行一个动作action 2)CCDirector::sharedDirector()-getActionManager()-pauseTarget(cocos2d::CCObject* pTarget)//暂停

Cocos2d-x提供的动作,只要是CCNode对象都可以使用。

1、常用操作如下:

1)runAction(cocos2d::CCAction* action)//执行一个动作action

2)CCDirector::sharedDirector()->getActionManager()->pauseTarget(cocos2d::CCObject* pTarget)//暂停目标pTarget对象的动作

3)CCDirector::sharedDirector()->getActionManager()->……//继续目标对象的动作

4)stopAction(cocos2d::CCAction* action)/停止的目标对象的动作

      stopActionByTag(int tag)//停止的目标动作对象的tag值

5)CCDirector::sharedDirector()->getActionManager()->removeAction(cocos2d::CCAction* action)//删除目标动作对象

6)CCDirector::sharedDirector()->getActionManager()->removeActionByTag(unsigned int tag,cocos2d::CCObject* pTarget)

参数1:要删除的动作的tag值

参数2:要删除动作所在的目标对象

7)pauseSchedulerAndActions()//暂停所有动作,连更新函数也全部暂停

      CCSet* CCDirector::sharedDirector->getActionManager()->pauseAllRunningActions()//暂停所有动作,将暂停的动作对象记录存放在CCSet集合中。

8)resumeSchedulerAndActions()

      CCDirector::sharedDirector()->getActionManager()->resumeTargets(cocos2d::CCSet* targetsToResume)//利用记录的已暂停的CCSet集合恢复动作

9)stopAllActions()//停止所有动作

10)CCDirector::sharedDirector()->getActionManager()->removeAllAction()//删除所有动作

2、常用49种动作详解

1)CCMoveTo::create(float duration,const CCPoint& position)//创建一个移动的动作

参数1:移动到目标坐标的时间

参数2:目标坐标

2)CCMoveBy::create(float duration,const CCPoint& position)//创建一个移动的动作,CCMoveBy支持reverse()函数,可以获取其反向动作

参数1:移动到目标坐标的时间

参数2:目标坐标

3)CCScaleTo::create(float duration,float s)//创建一个缩放的动作

参数1:达到缩放大小所需的时间(秒)

参数2:缩放的比例,其值=1,原大小;其值>1,放大;其值

4)CCScaleBy::create(float duration,float s)//创建一个缩放的动作,CCScaleBy支持reverse()函数,可以获取其反向动作

参数1:达到缩放大小所需的时间(秒)

参数2:缩放的比例

5)CCRotateTo::create(float duration,float fDeltaAngle)//创建一个旋转的动作

参数1:旋转到特定角度所需的时间(秒)

参数2:旋转的角度,范围是0-360

6)CCRotateBy::create(float duration,float fDeltaAngle)//创建一个旋转的动作,支持reverse()函数,可获取其反向动作

参数1:旋转到特定角度所需的时间(秒)

参数2:旋转的角度,范围是0-360

7)CCSkewTo::create(float t,float sx,float sy)//创建一个倾斜的动作

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

参数2:x轴的倾斜角度

参数3:y轴的倾斜角度

8)CCSkewBy::create(float t,float sx,float sy)//创建一个倾斜的动作,支持reverse()函数,可获取其方向动作

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

参数2:x轴的倾斜角度

参数3:y轴的倾斜角度

9)CCjumpTo::reate(float duration,const CCPoint& position,float height,int jumps)//创建一个跳的动作

参数1:完成动作用时(秒)

参数2:目标的位置

参数3:跳的高度

参数4:跳到目标点所需跳的次数

10)CCjumpBy::reate(float duration,const CCPoint& position,float height,int jumps)//创建一个跳的动作,支持reverse()函数,可获取其方向动作

参数1:完成动作用时(秒)

参数2:目标的位置

参数3:跳的高度

参数4:跳到目标点所需跳的次数

11)CCBezierTo::create(float t,const ccBezierConfig &c)//创建一个贝塞尔曲线运动的动作

参数1:贝塞尔曲线运动所需时间(秒)

参数2:ccBezierConfig结构体如下:

typedef struct _ccBezierConfig {

CCPoint endPosition;//结束点

CCPoint controlPoint_1;//控制点1

CCPoint controlPoint_2;//控制点2

}ccBezierConfig;

12)CCBezierBy::create(float t,const ccBezierConfig &c)//创建一个贝塞尔曲线运动的动作,支持reverse()函数,可获取其方向动作

参数1:贝塞尔曲线运动所需时间(秒)

参数2:ccBezierConfig结构体

13)CCFadeIn::create(float d)//创建一个渐变出现的动作,参数渐变所需时间(秒)

14)CCFadeOut::create(float d)//创建一个渐变消失的动作,参数渐变所需时间(秒)

15)CCTintTo::create(float duration,GLubyte red,GLubyte green,GLubyte blue)//创建一个色彩变化的动作

参数1:色彩变化所需时间(秒)

参数2:红色分量

参数3:绿色分量

参数4:蓝色分量

16)CCTintBy::create(float duration,GLubyte red,GLubyte green,GLubyte blue)//创建一个色彩变化的动作,支持reverse()函数,可获取其方向动作

17)CCBlink::create(float duration,unsigned int uBlinks)//创建一个闪烁的动作

参数1:闪烁完成的时间(秒)

参数2:闪烁的次数

18)CCDelayTime::create(float d)//创建一个延迟的动作,参数是延迟的时间(秒)

19)CCOrbitCamera::create(float t,float radius,float deltaRadius,float angleZ,float deltaAngleZ,float angleX,float deltaAngleX)//创建一个球面坐标轨迹进行旋转的动作

参数1:旋转轨迹所需时间

参数2:其实半径

参数3:半径差

参数4:起始Z角

参数5:旋转Z角差

参数6:起始X角

参数7:旋转X角差

20)CCCardinalSplineTo::create(float duration,CCPointArray* points,float tension)//创建一个样条曲线轨迹的动作

参数1:完成轨迹所需的时间

参数2:控制点的坐标数组

参数3:拟合度,其值=0,路径最柔和

21)CCCardinalSplineBy::create(float duration,CCPointArray* points,float tension)//创建一个样条曲线轨迹的动作,支持reverse()函数

22)CCCatmullRomTo::create(float dt,CCPointArray* points)//创建一个样条插值轨迹

参数1:完成轨迹的时间

参数2:控制点的坐标数组

23)CCCatmullRomBy::create(float dt,CCPointArray* points)//创建一个样条插值轨迹,支持reverse()函数

24)CCFollow::create(CCNode* pFollowedNode,const CCRect& rect=CCRectZero)//创建一个跟随的动作

参数1:跟随的目标对象

参数2:跟随范围,离开范围就不再跟随

25)CCEaseBounceIn::create(cocos2d::CCActionInterval* pAction)//让目标动作赋予弹力,且以目标动作起始位置开始反弹,参数是目标动作

26)CCEaseBounceOut::create(cocos2d::CCActionInterval* pAction)//让目标动作赋予弹力,且以目标动作结束位置开始反弹,参数是目标动作

27)CCEaseBounceInOut::create(cocos2d::CCActionInterval* pAction)//让目标动作赋予弹力,且以目标动作起始和结束位置开始反弹,参数是目标动作

28)CCEaseBackIn::create(cocos2d::CCActionInterval* pAction)//让目标动作赋予回力,且以目标动作起点位置作为回力点

29)CCEaseBackOut::create(cocos2d::CCActionInterval* pAction)//让目标动作赋予回力,且以目标动作终点位置作为回力点

30)CCEaseBackInOut::create(cocos2d::CCActionInterval* pAction)//让目标动作赋予回力,且以目标动作起点与终点位置作为回力点

31)CCEaseElasticIn::create(cocos2d::CCActionInterval* pAction)//让目标动作赋予弹性,且以目标动作起点位置赋予弹性

32)CCEaseElasticOut::create(cocos2d::CCActionInterval* pAction)//让目标动作赋予弹性,且以目标动作终点位置赋予弹性

33)CCEaseElasticInOut::create(cocos2d::CCActionInterval* pAction)//让目标动作赋予弹性,且以目标动作起点与终点位置赋予弹性

34)CCEaseExponentialIn::create(cocos2d::CCActionInterval* pAction)//让目标动作缓慢开始,参数 目标动作

35)CCEaseExponentialOut::create(cocos2d::CCActionInterval* pAction)//让目标动作缓慢终止,参数 目标动作

36)CCEaseExponentialInOut::create(cocos2d::CCActionInterval* pAction)//让目标动作缓慢开始缓慢终止,参数 目标动作

37)CCEaseRateAction::create(cocos2d::CCActionInterval* pAction,float fRate)//让目标动作设置速率,参数1:目标动作,参数2:速率

38)CCEaseSineIn::create(cocos2d::CCActionInterval* pAction)//让目标动作由慢至快

39)CCEaseSineOut::create(cocos2d::CCActionInterval* pAction)//让目标动作由快至慢

40)CCEaseSineInOut::create(cocos2d::CCActionInterval* pAction)//让目标动作由慢至快,再由快至慢

41)CCSpeed::create(cocos2d::CCActionInterval* pAction,float fSpeed)//让目标动作运行速度加倍。参数1:目标动作,参数2:倍速

42)CCSpawn::create(cocos2d::CCFiniteTimeAction* pAction1,...)//让多个动作同时执行,参数1:目标动作的可变参数

43)CCSequence::create(cocos2d::CCFiniteTimeAction* pAction1,...)//让多个动作按照前后顺序逐一执行,参数:目标动作的可变参数

如果需要对一个序列中的所有动作全部按顺序进行运动,可以使用如下形式操作。

<pre name="code" class="cpp"><pre name="code" class="cpp">CCActionInterval* move = CCMoveTo::create(2,cpp(300,sp->getPositionY()));
CCActionInterval* scale = CCScaleTo::create(2,3);
CCFiniteTimeAction* seq = CCSequence::create(move,scale,NULL);
sp->runAction(seq);


如果需要对一个序列中所有动作全部按顺序进行反向运动,可以使用如下形式操作:

CCActionInterval* move = CCMoveBy::create(2,cpp(300,sp->getPositionY()));
CCActionInterval* scale = CCScaleBy::create(2,3);
CCFiniteTimeAction* seq = CCSequence::create(move,scale,NULL);
sp->runAction(seq);
CCFiniteTimeAction* reverseSeq = CCSequence::create(seq,seq->reverse(),NULL);
sp->runAction(reverseSeq);
44)CCRepeat::create(cocos2d::CCFiniteTimeAction* pAction1,unsigned int times)//让目标动作重复运动,目标动作可以是CCSequence,CCSpawn

45)CCRepeatForever::create(cocos2d::CCFiniteTimeAction* pAction1,unsigned int times)//让目标动作进行永久性重复运动,目标如44

46)CCCallFunc::create(cocos2d::CCObject* pSelectorTarget,SEL_CallFunc selector)//创建一个回调动作,调用不带参数的回调方法

参数1:目标对象
参数2:目标回调函数

47)CCCallFuncN::create(cocos2d::CCObject* pSelectorTarget,SEL_CallFunc selector)//创建一个回调动作,调用带一个参数的回调方法

48)CCCallFuncND::create(cocos2d::CCObject* pSelectorTarget,SEL_CallFunc selector,void *d)//创建一个回调动作,调用带两个参数的回调方法

参数1:目标对象

参数2:目标回调函数

参数3:可以是任意类型

49)CCAnimate:动画。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn