转自:http://4137613.blog.51cto.com/4127613/767613
第一部分: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))); }
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); }
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)); }