第一部分: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:普通网格动作
摘自:http://4137613.blog.51cto.com/4127613/767613