cocos2d-x Action:其他动作

转自:http://4137613.blog.51cto.com/4127613/767613

第一部分:CCFollow跟随动作

CCFollow动作,可以让一个节点跟随另一个节点做位移。
他有两个静态工厂方法,后者可以设置一个跟随范围,离开范围就不再跟随。

bool    initWithTarget (CCNode *pFollowedNode) 
bool    initWithTarget (CCNode *pFollowedNode, const CCRect &rect) 
CCFollow经常用来设置layer跟随sprite,可以实现类似摄像机跟拍的效果。cocos2d-x中的tests里,有类似的例子,代码如下:

void ActionFollow::onEnter() 
{ 
    ActionsDemo::onEnter(); 
 
    centerSprites(1); 
    CCSize s = CCDirector::sharedDirector()->getWinSize(); 
 
    m_grossini->setPosition(CCPointMake(-200, s.height / 2)); 
    CCActionInterval* move      = CCMoveBy::actionWithDuration(2, CCPointMake(s.width * 3, 0)); 
    CCActionInterval* move_back = move->reverse(); 
    CCFiniteTimeAction* seq       = CCSequence::actions(move, move_back, NULL); 
    CCAction* rep               = CCRepeatForever::actionWithAction((CCActionInterval*)seq); 
 
    m_grossini->runAction(rep); 
 
    this->runAction(CCFollow::actionWithTarget(m_grossini, CCRectMake(0, 0, s.width * 2 - 100, s.height))); 
} 

第二部分:CCDelayTime延时动作
CCDelayTime是一个延时若干秒的动作,最常见的用法就是在一个CCSequence序列动作中,打入若干延时时间,让动作的执行速度慢下来,不至于眼花缭乱,让人反应不过来。
 
cocos2d-x中的tests里,有类似的例子,代码如下:
void ActionDelayTime::onEnter() 
{ 
    ActionsDemo::onEnter(); 
 
    alignSpritesLeft(1); 
 
    CCActionInterval*  move = CCMoveBy::actionWithDuration(1, CCPointMake(150,0)); 
    CCFiniteTimeAction*  action = CCSequence::actions( move, CCDelayTime::actionWithDuration(2), move, NULL); 
 
    m_grossini->runAction(action); 
} 

第三部分:CCProgressFromTo与CCProgressTo 进度动作

进度动作,也是一种从无到有逐渐绘制的动作,和淡入淡出的作用类似。

注意进度动作的执行节点为CCProgressTimer,而非我们常用的CCSprite。我们在使用进度动作时,需要指定绘制类型。
 
cocos2d-x一种提供了6种类型的枚举值:
typedef enum { 
            /// Radial Counter-Clockwise 逆时针 
            kCCProgressTimerTypeRadialCCW, 
            /// Radial ClockWise 顺时针 
            kCCProgressTimerTypeRadialCW, 
            /// Horizontal Left-Right 从左往右 
            kCCProgressTimerTypeHorizontalBarLR, 
            /// Horizontal Right-Left 从右往左 
            kCCProgressTimerTypeHorizontalBarRL, 
            /// Vertical Bottom-top 从下往上 
            kCCProgressTimerTypeVerticalBarBT, 
            /// Vertical Top-Bottom 从上往下 
            kCCProgressTimerTypeVerticalBarTB, 
} CCProgressTimerType; 

cocos2d-x中的tests里,有全部的进度动作的例子,其中按时针绘制的例子代码如下:

void SpriteProgressToHorizontal::onEnter() 
{ 
            SpriteDemo::onEnter(); 
             
            CCSize s = CCDirector::sharedDirector()->getWinSize(); 
             
            CCProgressTo *to1 = CCProgressTo::actionWithDuration(2, 100); 
            CCProgressTo *to2 = CCProgressTo::actionWithDuration(2, 100); 
             
            CCProgressTimer *left = CCProgressTimer::progressWithFile(s_pPathSister1); 
            left->setType( kCCProgressTimerTypeHorizontalBarLR );//设置动作类型 
            addChild(left); 
            left->setPosition(CCPointMake(100, s.height/2)); 
            left->runAction( CCRepeatForever::actionWithAction(to1)); 
             
            CCProgressTimer *right = CCProgressTimer::progressWithFile(s_pPathSister2); 
            right->setType( kCCProgressTimerTypeHorizontalBarRL );//设置动作类型 
            addChild(right); 
            right->setPosition(CCPointMake(s.width-100, s.height/2)); 
            right->runAction( CCRepeatForever::actionWithAction(to2)); 
} 

第四部分:CCGridAction 网格动作家族

网格动作,是一种特殊的变换效果,类似于特效,可以实现全屏幕的,翻转,抖动,震荡,水波纹等。CCGridAction是所有网格动作的基类,他有两个派生类
CCTiledGrid3DAction:基于Tiled的网格动作
CCGrid3DAction:普通网格动作

这些动作的相关例子,都在cocos2d-x的tests中的EffectsTest里。因为用法简单,但是数量庞大,又不是特别常用,而且效果用语言很难准确描述,就不赘述了。直接看代码就行。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值