CCActionInterval(CCSkewTo CCJumpBy CCBezierBy CCBlink CCTintTo CCReverseTime CCAnimate CCTargetedAc)



#ifndef __ACTION_CCINTERVAL_ACTION_H__

#define __ACTION_CCINTERVAL_ACTION_H__


#include "base_nodes/CCNode.h"

#include "CCAction.h"

#include "CCProtocols.h"

#include "sprite_nodes/CCSpriteFrame.h"

#include "sprite_nodes/CCAnimation.h"

#include <vector>


NS_CC_BEGIN

/** 

@brief An interval action is an action that takes place(发生;举行;就位)within a certain period(周期 期间) of time.

It has an start time, and a finish time. The finish time is the parameter

duration plus the start time.


These CCActionInterval actions have some interesting(有趣的) properties(性能;道具,内容(property的复数形式)), like:

- They can run normally (default)

- They can run reversed with the reverse method

- They can run with the time altered(改变) with the Accelerate(加速), AccelDeccel(减速) and Speed actions.


For example, you can simulate(模仿) a Ping Pong effect running the action normally and

then running it again in Reverse mode.


Example:


CCAction *pingPongAction = CCSequence::actions(action, action->reverse(), NULL);

*/

class CC_DLL CCActionInterval : public CCFiniteTimeAction//延时动作

{

public:

    /** how many seconds had elapsed since the actions started to run. */

    inline float getElapsed(void) { return m_elapsed; }//距离上一次update的流逝时间


    /** initializes the action */

    bool initWithDuration(float d);


    /** returns true if the action has finished */

    virtual bool isDone(void);//动作是否完成


    virtual CCObject* copyWithZone(CCZone* pZone);

    virtual void step(float dt);

    virtual void startWithTarget(CCNode *pTarget);

    /** returns a reversed action */

    virtual CCActionInterval* reverse(void);


public:


    /** creates the action */

    static CCActionInterval* create(float d);


public:

    //extension in CCGridAction 

    void setAmplitudeRate(float amp);  //Amplitude 振幅  设置振幅

    float getAmplitudeRate(void);  //得到振幅


protected:

    float m_elapsed;

    bool   m_bFirstTick;//是否第一次就开始动作

};


///

CCSequence* CCSequence::create(CCFiniteTimeAction *pAction1, ...)

  内部调用了createWithVariableList,从实现可以看出这是一个递归调用。

  createWithVariableList

  //获取动作列表,创建CCSequence

  CCSequence* CCSequence::createWithVariableList(CCFiniteTimeAction *pAction1, va_list args)

  {

  CCFiniteTimeAction *pNow;//当前动作

  CCFiniteTimeAction *pPrev = pAction1;//第一个动作

  bool bOneAction = true;//只有一个动作的标志位

  while (pAction1)

  {

  pNow = va_arg(args, CCFiniteTimeAction*);//获取当前动作

  if (pNow)//如果存在

  {

  pPrev = createWithTwoActions(pPrev, pNow);//用前两个动作创建CCSequence并赋给第一个动作

  bOneAction = false;//置false

  }

  else//如果不存在

  {

  // If only one action is added to CCSequence, make up a CCSequence by adding a simplest finite time action.

  if (bOneAction)//如果只有一个动作

  {

  pPrev = createWithTwoActions(pPrev, ExtraAction::create());

  }

  break;//跳出循环

  }

  }

  return ((CCSequence*)pPrev);//返回第一个动作

  }

假如有3个动作要被串联,则先把第1个和第2个串联一个CCSequence,再把这个CCSequence和第3个动作串联成最终的CCSequence,然后返回。从CCSequence的成员变量可以看到:

  动作对象指针成员变量

  1 CCFiniteTimeAction *m_pActions[2];//表明只包含2个动作对象指针

  使用递归多少会降低程序的运行效率,但是却可以换来代码的简洁性,同样的CCSpawn也是这么实现的。 在createWithTwoActions中,调用了initWithTwoActions函数,实现了把两个动作串成一个CCSequence,关键代码如下:

  initWithTwoActions

  float d = pActionOne->getDuration() + pActionTwo->getDuration();//获取两个动作的duration

  CCActionInterval::initWithDuration(d);//赋给新的CCSequence

  m_pActions[0] = pActionOne;//同时把两个动作赋给m_pActions指针数组

  pActionOne->retain();

  m_pActions[1] = pActionTwo;

  pActionTwo->retain();

  2.2.duration

  从示例可以看出,闪烁动画blink的duration是0.5s,那CCRepeatForever呢?1s?当然不是,1s只是帧动画animate的帧间间隔,每个帧动画包含2帧,而CCRepeatForever的duration是0。因此,当示例中的闪烁动画blink和重复动画repeat串联成CCSequence sequence的时候,sequence的duration就变成0.5+0=0.5s,这很重要。

  2.3.m_split

  CCSequence中有这么一个成员变量

  m_split

  1 float m_split;//记录了第一个动画时长占总时长的比例,也就是2个动画的时长分界

  当执行runAction的时候,CCSequence会调用

  startWithTarget

  void CCSequence::startWithTarget(CCNode *pTarget)

  {

  CCActionInterval::startWithTarget(pTarget);

  m_split = m_pActions[0]->getDuration() / m_fDuration;//获取第一个动画占总时长的比例

  m_last = -1;

  }

  而这里由于blink占了0.5s,repeat占了0s,总时长0.5s,所以m_split是0.5/0.5=1。blink占满了整个CCSequence,所以CCSequence无法执行repeat。

  这时候再来看CCSequence::update(float dt)函数的执行,就会恍然大悟了。

  update

  int found = 0;//当前播放动作索引

  float new_t = 0.0f;//新播放进度

  if( t < m_split ) {//播放进度<分界进度

  found = 0;//设置当前播放的是第一个动作

  if( m_split != 0 )//如果第一个动作时长占比!=0

  new_t = t / m_split;//计算出第一个动作新的播放进度

  else

  new_t = 1;//设置第一个已播放完毕

  } else {//播放进度>=分界进度

  found = 1;//设置当前播放的是第二个动作

  if ( m_split == 1 )//如果第一个动作时长占比==1

  new_t = 1;//设置第二个动作已完成

  else

  new_t = (t-m_split) / (1 - m_split );//计算出第二个动作新的播放进度

  }

  3.注意

  (1)CCSpawn也会有这个问题,所以CCSpawn也无法执行加入其中的CCRepeatForever动作。

  (2)CCRepeatForever的反转动作也是无效了,一个不会停止的动作从什么地方开始反转?当然你可以先把动作反转了再加入CCRepeatForever中,这是没问题的。

  4.解决方案

  (1)对于同时动作,不使用CCSpawn,采用分别执行

  分别执行

  close->runAction(blink);

  close->runAction(repeat);

  (2)对于连续动作,不直接往CCSequence中加入CCRepeatForever,而是把CCRepeatForever放入瞬时动作CCCallFunc中,再把CCCallFunc加入CCSequence中执行。

  CCSequence串联

  close=CCSprite::create("CloseNormal.png");

  CCBlink* blink=CCBlink::create(0.5f,10);

  CCCallFunc* callFunc=CCCallFunc::create(this,callfunc_selector(TestScene::repeatFunc));//创建CCCallFunc对象

  CCSequence* sequence=CCSequence::create(blink,callFunc,NULL);//把CCCallFunc对象加入CCSequence中

  close->setPosition(ccp(240,160));

  this->addChild(close);

  close->runAction(sequence);

  void TestScene::repeatFunc()

  {

  CCAnimation* animation=CCAnimation::create();

  animation->addSpriteFrameWithFileName("CloseNormal.png");

  animation->addSpriteFrameWithFileName("CloseSelected.png");

  animation->setDelayPerUnit(1.0f);

  CCAnimate* animate=CCAnimate::create(animation);

  CCRepeatForever* repeat=CCRepeatForever::create(animate);

  close->runAction(repeat);

  }

  (3)对于CCAnimation帧动画,可以设置循环属性,而不使用CCRepeatForever。

  setLoops

  1  animation->setLoops(-1);

  5.总结

  虽然CCRepeatForever也同样继承于CCActionInterval,理论上是延时动作的子类,但是和一般的延时动作又有很大的不同,所以平时在使用的时候必须很小心,不能当成一般的CCActionInterval使用。而在cocos2d-x动作的分类上是不是应该把它从CCAction继承出来会比较好一点?




class CC_DLL CCSequence : public CCActionInterval

{

public:

    ~CCSequence(void);


    /** initializes the action */

    bool initWithTwoActions(CCFiniteTimeAction *pActionOne, CCFiniteTimeAction *pActionTwo);


    virtual CCObject* copyWithZone(CCZone* pZone);

    virtual void startWithTarget(CCNode *pTarget);

    virtual void stop(void);//暂停动作

    virtual void update(float t);

    virtual CCActionInterval* reverse(void);


public:



    /** helper constructor to create an array of sequenceable actions */

    static CCSequence* create(CCFiniteTimeAction *pAction1, ...);

    /** helper constructor to create an array of sequenceable actions given an array */

    static CCSequence* create(CCArray *arrayOfActions);

    /** helper constructor to create an array of sequence-able actions */

    static CCSequence* createWithVariableList(CCFiniteTimeAction *pAction1, va_list args);

    /** creates the action */

    static CCSequence* createWithTwoActions(CCFiniteTimeAction *pActionOne, CCFiniteTimeAction *pActionTwo);


protected:

    CCFiniteTimeAction *m_pActions[2];//两个动作即可 通过递归

    float m_split;

    int m_last;

};


class CC_DLL CCRepeat : public CCActionInterval

{

public:

    ~CCRepeat(void);


    /** initializes a CCRepeat action. Times is an unsigned integer between 1 and pow(2,30) */

    bool initWithAction(CCFiniteTimeAction *pAction, unsigned int times);


    virtual CCObject* copyWithZone(CCZone* pZone);

    virtual void startWithTarget(CCNode *pTarget);

    virtual void stop(void);

    virtual void update(float dt);

///

// issue #80. Instead of hooking step:, hook update: since it can be called by any 

// container action like CCRepeat, CCSequence, CCEase, etc..

void CCRepeat::update(float dt)

{

    if (dt >= m_fNextDt)

    {

        while (dt > m_fNextDt && m_uTotal < m_uTimes)

        {


            m_pInnerAction->update(1.0f);

            m_uTotal++;


            m_pInnerAction->stop();

            m_pInnerAction->startWithTarget(m_pTarget);

            m_fNextDt += m_pInnerAction->getDuration()/m_fDuration;

        }


        // fix for issue #1288, incorrect end value of repeat

        if(dt >= 1.0f && m_uTotal < m_uTimes) 

        {

            m_uTotal++;

        }


        // don't set an instant action back or update it, it has no use because it has no duration

        if (!m_bActionInstant)

        {

            if (m_uTotal == m_uTimes)

            {

                m_pInnerAction->update(1);

                m_pInnerAction->stop();

            }

            else

            {

                // issue #390 prevent jerk, use right update

                m_pInnerAction->update(dt - (m_fNextDt - m_pInnerAction->getDuration()/m_fDuration));

            }

        }

    }

    else

    {

        m_pInnerAction->update(fmodf(dt * m_uTimes,1.0f));

    }

}


//



    virtual bool isDone(void);

    virtual CCActionInterval* reverse(void);


    inline void setInnerAction(CCFiniteTimeAction *pAction)

    {

        if (m_pInnerAction != pAction)

        {

            CC_SAFE_RETAIN(pAction);

            CC_SAFE_RELEASE(m_pInnerAction);

            m_pInnerAction = pAction;

        }

    }


    inline CCFiniteTimeAction* getInnerAction()

    {

        return m_pInnerAction;

    }


public:


    /** creates a CCRepeat action. Times is an unsigned integer between 1 and pow(2,30) */

    static CCRepeat* create(CCFiniteTimeAction *pAction, unsigned int times);

protected:

    unsigned int m_uTimes;

    unsigned int m_uTotal;

    float m_fNextDt;

    bool m_bActionInstant;

    /** Inner action */

    CCFiniteTimeAction *m_pInnerAction;

};


/** @brief Repeats an action for ever.

To repeat the an action for a limited number of times use the Repeat action.

@warning This action can't be Sequenceable because it is not an IntervalAction

*/

class CC_DLL CCRepeatForever : public CCActionInterval

{

public:

    CCRepeatForever()

        : m_pInnerAction(NULL)

    {}

    virtual ~CCRepeatForever();


    /** initializes the action */

    bool initWithAction(CCActionInterval *pAction);

    virtual CCObject* copyWithZone(CCZone *pZone);

    virtual void startWithTarget(CCNode* pTarget);

    virtual void step(float dt);


void CCRepeatForever::step(float dt)

{

    m_pInnerAction->step(dt);

    if (m_pInnerAction->isDone())

    {

        float diff = m_pInnerAction->getElapsed() - m_pInnerAction->getDuration();

        m_pInnerAction->startWithTarget(m_pTarget);

        // to prevent jerk. issue #390, 1247

        m_pInnerAction->step(0.0f);

        m_pInnerAction->step(diff);

    }

}


/



    virtual bool isDone(void);

    virtual CCActionInterval* reverse(void);


    inline void setInnerAction(CCActionInterval *pAction)

    {

        if (m_pInnerAction != pAction)

        {

            CC_SAFE_RELEASE(m_pInnerAction);

            m_pInnerAction = pAction;

            CC_SAFE_RETAIN(m_pInnerAction);

        }

    }


    inline CCActionInterval* getInnerAction()

    {

        return m_pInnerAction;

    }


public:


    /** creates the action */

    static CCRepeatForever* create(CCActionInterval *pAction);

protected:

    /** Inner action */

    CCActionInterval *m_pInnerAction;

};


/** @brief Spawn a new action immediately

 */

class CC_DLL CCSpawn : public CCActionInterval

{

public:

    ~CCSpawn(void);


    /** initializes the Spawn action with the 2 actions to spawn */

    bool initWithTwoActions(CCFiniteTimeAction *pAction1, CCFiniteTimeAction *pAction2);


    virtual CCObject* copyWithZone(CCZone* pZone);

    virtual void startWithTarget(CCNode *pTarget);

    virtual void stop(void);

    virtual void update(float time);

//

void CCSpawn::update(float time)

{

    if (m_pOne)

    {

        m_pOne->update(time);

    }

    if (m_pTwo)

    {

        m_pTwo->update(time);

    }

}

//

    virtual CCActionInterval* reverse(void);


public:


    /** helper constructor to create an array of spawned actions */

    static CCSpawn* create(CCFiniteTimeAction *pAction1, ...);

    

    /** helper constructor to create an array of spawned actions */

    static CCSpawn* createWithVariableList(CCFiniteTimeAction *pAction1, va_list args);


    /** helper constructor to create an array of spawned actions given an array */

    static CCSpawn* create(CCArray *arrayOfActions);


    /** creates the Spawn action */

    static CCSpawn* createWithTwoActions(CCFiniteTimeAction *pAction1, CCFiniteTimeAction *pAction2);


protected:

    CCFiniteTimeAction *m_pOne;

    CCFiniteTimeAction *m_pTwo;

};


/** @brief Rotates a CCNode object to a certain angle by modifying it's

 rotation attribute.

 The direction will be decided by the shortest angle.

*/ 

class CC_DLL CCRotateTo : public CCActionInterval  //旋转动作

{

public:

    /** creates the action */

    static CCRotateTo* create(float fDuration, float fDeltaAngle);

    /** initializes the action */

    bool initWithDuration(float fDuration, float fDeltaAngle);

    

    /** creates the action with separate rotation angles */

    static CCRotateTo* create(float fDuration, float fDeltaAngleX, float fDeltaAngleY);

    virtual bool initWithDuration(float fDuration, float fDeltaAngleX, float fDeltaAngleY);

//

bool CCRotateTo::initWithDuration(float fDuration, float fDeltaAngleX, float fDeltaAngleY)

{

    if (CCActionInterval::initWithDuration(fDuration))

    {

        m_fDstAngleX = fDeltaAngleX;

        m_fDstAngleY = fDeltaAngleY;

        

        return true;

    }

    

    return false;

}

//


    virtual CCObject* copyWithZone(CCZone* pZone);

    virtual void startWithTarget(CCNode *pTarget);

//

void CCRotateTo::startWithTarget(CCNode *pTarget)

{

    CCActionInterval::startWithTarget(pTarget);

    

    // Calculate X

    m_fStartAngleX = pTarget->getRotationX();//------

    if (m_fStartAngleX > 0)

    {

        m_fStartAngleX = fmodf(m_fStartAngleX, 360.0f);

    }

    else

    {

        m_fStartAngleX = fmodf(m_fStartAngleX, -360.0f);

    }


    m_fDiffAngleX = m_fDstAngleX - m_fStartAngleX;//-----

    if (m_fDiffAngleX > 180)

    {

        m_fDiffAngleX -= 360;

    }

    if (m_fDiffAngleX < -180)

    {

        m_fDiffAngleX += 360;

    }

    

    //Calculate Y: It's duplicated(复制) from calculating X since the rotation wrap should be the same

    m_fStartAngleY = m_pTarget->getRotationY();


    if (m_fStartAngleY > 0)

    {

        m_fStartAngleY = fmodf(m_fStartAngleY, 360.0f);

    }

    else

    {

        m_fStartAngleY = fmodf(m_fStartAngleY, -360.0f);

    }


    m_fDiffAngleY = m_fDstAngleY - m_fStartAngleY;

    if (m_fDiffAngleY > 180)

    {

        m_fDiffAngleY -= 360;

    }


    if (m_fDiffAngleY < -180)

    {

        m_fDiffAngleY += 360;

    }

}


//


    virtual void update(float time);

/

void CCRotateTo::update(float time)

{

    if (m_pTarget)

    {

        m_pTarget->setRotationX(m_fStartAngleX + m_fDiffAngleX * time);

        m_pTarget->setRotationY(m_fStartAngleY + m_fDiffAngleY * time);

    }

}

protected:

    float m_fDstAngleX;  //destination  通过init

    float m_fStartAngleX;//target 中获得

    float m_fDiffAngleX;//上面两者之差

    

    float m_fDstAngleY;

    float m_fStartAngleY;

    float m_fDiffAngleY;

};


/** @brief Rotates a CCNode object clockwise a number of degrees by modifying it's rotation attribute.

*/

class CC_DLL CCRotateBy : public CCActionInterval

{

public:

    /** creates the action */

    static CCRotateBy* create(float fDuration, float fDeltaAngle);

    /** initializes the action */

    bool initWithDuration(float fDuration, float fDeltaAngle);

    

    static CCRotateBy* create(float fDuration, float fDeltaAngleX, float fDeltaAngleY);

    bool initWithDuration(float fDuration, float fDeltaAngleX, float fDeltaAngleY);


    virtual CCObject* copyWithZone(CCZone* pZone);

    virtual void startWithTarget(CCNode *pTarget);

    virtual void update(float time);

    virtual CCActionInterval* reverse(void);

    

protected:

    float m_fAngleX;

    float m_fStartAngleX;

    float m_fAngleY;

    float m_fStartAngleY;

};


/**  Moves a CCNode object x,y pixels by modifying it's position attribute.

 x and y are relative to the position of the object.

 Several CCMoveBy actions can be concurrently called, and the resulting

 movement will be the sum of individual movements.

 @since v2.1beta2-custom

 */

class CC_DLL CCMoveBy : public CCActionInterval  //移动动作 同旋转动作 position代替angle

{

public:

    /** initializes the action */

    bool initWithDuration(float duration, const CCPoint& deltaPosition);


    virtual CCObject* copyWithZone(CCZone* pZone);

    virtual void startWithTarget(CCNode *pTarget);

    virtual CCActionInterval* reverse(void);

    virtual void update(float time);


public:

    /** creates the action */

    static CCMoveBy* create(float duration, const CCPoint& deltaPosition);

protected:

    CCPoint m_positionDelta;

    CCPoint m_startPosition;

    CCPoint m_previousPosition;

};


/** Moves a CCNode object to the position x,y. x and y are absolute coordinates by modifying it's position attribute.

 Several CCMoveTo actions can be concurrently called, and the resulting

 movement will be the sum of individual movements.

 @since v2.1beta2-custom

 */

class CC_DLL CCMoveTo : public CCMoveBy

{

public:

    /** initializes the action */

    bool initWithDuration(float duration, const CCPoint& position);


    virtual CCObject* copyWithZone(CCZone* pZone);

    virtual void startWithTarget(CCNode *pTarget);


public:

    /** creates the action */

    static CCMoveTo* create(float duration, const CCPoint& position);

protected:

    CCPoint m_endPosition;

};


/** Skews a CCNode object to given angles by modifying it's skewX and skewY attributes

@since v1.0

*/

class CC_DLL CCSkewTo : public CCActionInterval//扭曲动作 同旋转动作 m_fSkewX代替angle

{

public:

    CCSkewTo();

    virtual bool initWithDuration(float t, float sx, float sy);

    virtual CCObject* copyWithZone(CCZone* pZone);

    virtual void startWithTarget(CCNode *pTarget);

    virtual void update(float time);


public:


    /** creates the action */

    static CCSkewTo* create(float t, float sx, float sy);

protected:

    float m_fSkewX;

    float m_fSkewY;

    float m_fStartSkewX;

    float m_fStartSkewY;

    float m_fEndSkewX;

    float m_fEndSkewY;

    float m_fDeltaX;

    float m_fDeltaY;

};


/** Skews a CCNode object by skewX and skewY degrees

@since v1.0

*/

class CC_DLL CCSkewBy : public CCSkewTo

{

public:

    virtual bool initWithDuration(float t, float sx, float sy);

    virtual void startWithTarget(CCNode *pTarget);

    virtual CCActionInterval* reverse(void);


public:


    /** creates the action */

    static CCSkewBy* create(float t, float deltaSkewX, float deltaSkewY);

};


/** @brief Moves a CCNode object simulating a parabolic jump movement by modifying it's position attribute.

*/

class CC_DLL CCJumpBy : public CCActionInterval//跳跃动作

{

public:

    /** initializes the action */

    bool initWithDuration(float duration, const CCPoint& position, float height, unsigned int jumps);


    virtual CCObject* copyWithZone(CCZone* pZone);

    virtual void startWithTarget(CCNode *pTarget);

    virtual void update(float time);

    virtual CCActionInterval* reverse(void);


public:

    /** creates the action */

    static CCJumpBy* create(float duration, const CCPoint& position, float height, unsigned int jumps);

protected:

    CCPoint         m_startPosition;

    CCPoint         m_delta;

    float           m_height;

    unsigned int    m_nJumps;

    CCPoint         m_previousPos;

};


/** @brief Moves a CCNode object to a parabolic position simulating a jump movement by modifying it's position attribute.

*/ 

class CC_DLL CCJumpTo : public CCJumpBy

{

public:

    virtual void startWithTarget(CCNode *pTarget);

    virtual CCObject* copyWithZone(CCZone* pZone);


public:

    /** creates the action */

    static CCJumpTo* create(float duration, const CCPoint& position, float height, int jumps);

};


/** @typedef bezier configuration structure

 */

typedef struct _ccBezierConfig {  //贝塞尔曲线动作 详细->其它->贝塞尔曲线

    //! end position of the bezier

    CCPoint endPosition;

    //! Bezier control point 1

    CCPoint controlPoint_1;

    //! Bezier control point 2

    CCPoint controlPoint_2;

} ccBezierConfig;


/** @brief An action that moves the target with a cubic Bezier curve by a certain distance.

 */

class CC_DLL CCBezierBy : public CCActionInterval

{

public:

    /** initializes the action with a duration and a bezier configuration */

    bool initWithDuration(float t, const ccBezierConfig& c);


    virtual CCObject* copyWithZone(CCZone* pZone);

    virtual void startWithTarget(CCNode *pTarget);

    virtual void update(float time);

    virtual CCActionInterval* reverse(void);


public:

    /** creates the action with a duration and a bezier configuration */

    static CCBezierBy* create(float t, const ccBezierConfig& c);

protected:

    ccBezierConfig m_sConfig;

    CCPoint m_startPosition;

    CCPoint m_previousPosition;

};


/** @brief An action that moves the target with a cubic Bezier curve to a destination point.

 @since v0.8.2

 */

class CC_DLL CCBezierTo : public CCBezierBy

{

public:

    virtual void startWithTarget(CCNode *pTarget);

    virtual CCObject* copyWithZone(CCZone* pZone);


public:


    /** creates the action with a duration and a bezier configuration */

    static CCBezierTo* create(float t, const ccBezierConfig& c);

    bool initWithDuration(float t, const ccBezierConfig &c);

    

protected:

    ccBezierConfig m_sToConfig;

};


/** @brief Scales a CCNode object to a zoom factor by modifying it's scale attribute.

 @warning This action doesn't support "reverse"

 */

class CC_DLL CCScaleTo : public CCActionInterval  //缩放动作

{

public:

    /** initializes the action with the same scale factor for X and Y */

    bool initWithDuration(float duration, float s);


    /** initializes the action with and X factor and a Y factor */

    bool initWithDuration(float duration, float sx, float sy);


    virtual CCObject* copyWithZone(CCZone* pZone);

    virtual void startWithTarget(CCNode *pTarget);

    virtual void update(float time);


public:


    /** creates the action with the same scale factor for X and Y */

    static CCScaleTo* create(float duration, float s);


    /** creates the action with and X factor and a Y factor */

    static CCScaleTo* create(float duration, float sx, float sy);

protected:

    float m_fScaleX;

    float m_fScaleY;

    float m_fStartScaleX;

    float m_fStartScaleY;

    float m_fEndScaleX;

    float m_fEndScaleY;

    float m_fDeltaX;

    float m_fDeltaY;

};


/** @brief Scales a CCNode object a zoom factor by modifying it's scale attribute.

*/

class CC_DLL CCScaleBy : public CCScaleTo

{

public:

    virtual void startWithTarget(CCNode *pTarget);

    virtual CCActionInterval* reverse(void);

    virtual CCObject* copyWithZone(CCZone* pZone);


public:


    /** creates the action with the same scale factor for X and Y */

    static CCScaleBy* create(float duration, float s);


    /** creates the action with and X factor and a Y factor */

    static CCScaleBy* create(float duration, float sx, float sy);

};


/** @brief Blinks a CCNode object by modifying it's visible attribute

*/

class CC_DLL CCBlink : public CCActionInterval//闪烁动作

{

public:

    /** initializes the action */

    bool initWithDuration(float duration, unsigned int uBlinks);


    virtual CCObject* copyWithZone(CCZone* pZone);

    virtual void update(float time);

    virtual CCActionInterval* reverse(void);


public:


    /** creates the action */

    static CCBlink* create(float duration, unsigned int uBlinks);

    

    virtual void startWithTarget(CCNode *pTarget);

    virtual void stop();

    

protected:

    unsigned int m_nTimes;

    bool m_bOriginalState;

};


/** @brief Fades In an object that implements the CCRGBAProtocol protocol. It modifies the opacity from 0 to 255.

 The "reverse" of this action is FadeOut

 */

class CC_DLL CCFadeIn : public CCActionInterval//淡入淡出动作

{

public:

    virtual void update(float time);

    virtual CCActionInterval* reverse(void);

    virtual CCObject* copyWithZone(CCZone* pZone);


public:

    /** creates the action */

    static CCFadeIn* create(float d);

};


/** @brief Fades Out an object that implements the CCRGBAProtocol protocol. It modifies the opacity from 255 to 0.

 The "reverse" of this action is FadeIn

*/

class CC_DLL CCFadeOut : public CCActionInterval

{

public:

    virtual void update(float time);

    virtual CCActionInterval* reverse(void);

    virtual CCObject* copyWithZone(CCZone* pZone);


public:


    /** creates the action */

    static CCFadeOut* create(float d);

};


/** @brief Fades an object that implements the CCRGBAProtocol protocol. It modifies the opacity from the current value to a custom one.

 @warning This action doesn't support "reverse"

 */

class CC_DLL CCFadeTo : public CCActionInterval

{

public:

    /** initializes the action with duration and opacity */

    bool initWithDuration(float duration, GLubyte opacity);


    virtual CCObject* copyWithZone(CCZone* pZone);

    virtual void startWithTarget(CCNode *pTarget);

    virtual void update(float time);


public:

    /** creates an action with duration and opacity */

    static CCFadeTo* create(float duration, GLubyte opacity);

protected:

    GLubyte m_toOpacity;

    GLubyte m_fromOpacity;

};


/** @brief Tints a CCNode that implements the CCNodeRGB protocol from current tint to a custom one.

 @warning This action doesn't support "reverse"

 @since v0.7.2

*/

class CC_DLL CCTintTo : public CCActionInterval//CCTintTo、CCTintBy是将sprite的颜色调到你想设置的目标颜色

{

public:

    /** initializes the action with duration and color */

    bool initWithDuration(float duration, GLubyte red, GLubyte green, GLubyte blue);


    virtual CCObject* copyWithZone(CCZone* pZone);

    virtual void startWithTarget(CCNode *pTarget);

    virtual void update(float time);


public:

    /** creates an action with duration and color */

    static CCTintTo* create(float duration, GLubyte red, GLubyte green, GLubyte blue);

protected:

    ccColor3B m_to;

    ccColor3B m_from;

};


/** @brief Tints a CCNode that implements the CCNodeRGB protocol from current tint to a custom one.

 @since v0.7.2

 */

class CC_DLL CCTintBy : public CCActionInterval

{

public:

    /** initializes the action with duration and color */

    bool initWithDuration(float duration, GLshort deltaRed, GLshort deltaGreen, GLshort deltaBlue);


    virtual CCObject* copyWithZone(CCZone* pZone);

    virtual void startWithTarget(CCNode *pTarget);

    virtual void update(float time);

    virtual CCActionInterval* reverse(void);


public:

    /** creates an action with duration and color */

    static CCTintBy* create(float duration, GLshort deltaRed, GLshort deltaGreen, GLshort deltaBlue);

protected:

    GLshort m_deltaR;

    GLshort m_deltaG;

    GLshort m_deltaB;


    GLshort m_fromR;

    GLshort m_fromG;

    GLshort m_fromB;

};


/** @brief Delays the action a certain amount of seconds

*/

class CC_DLL CCDelayTime : public CCActionInterval//延迟动作

{

public:

    virtual void update(float time);

    virtual CCActionInterval* reverse(void);

    virtual CCObject* copyWithZone(CCZone* pZone);


public:


    /** creates the action */

    static CCDelayTime* create(float d);

};


/** @brief Executes an action in reverse order, from time=duration to time=0

 

 @warning Use this action carefully. This action is not

 sequenceable. Use it as the default "reversed" method

 of your own actions, but using it outside the "reversed"

 scope is not recommended.

*/

class CC_DLL CCReverseTime : public CCActionInterval//反动作 修饰类动作 用于moveto这种没有reserve函数的

{

public:

    ~CCReverseTime(void);

    CCReverseTime();


    /** initializes the action */

    bool initWithAction(CCFiniteTimeAction *pAction); 


    virtual CCObject* copyWithZone(CCZone* pZone);

    virtual void startWithTarget(CCNode *pTarget);

    virtual void stop(void);

    virtual void update(float time);

    virtual CCActionInterval* reverse(void);


public:

    /** creates the action */

    static CCReverseTime* create(CCFiniteTimeAction *pAction);

protected:

    CCFiniteTimeAction *m_pOther;

};


class CCTexture2D;

/** @brief Animates a sprite given the name of an Animation */

class CC_DLL CCAnimate : public CCActionInterval//动画动作 需要CCAnimation来初始化

{

public:

    CCAnimate();

    ~CCAnimate();


    /** initializes the action with an Animation and will restore the original frame when the animation is over */

    bool initWithAnimation(CCAnimation *pAnimation);



    virtual CCObject* copyWithZone(CCZone* pZone);

    virtual void startWithTarget(CCNode *pTarget);

    virtual void stop(void);

    virtual void update(float t);

    virtual CCActionInterval* reverse(void);


public:

    /** creates the action with an Animation and will restore the original frame when the animation is over */

    static CCAnimate* create(CCAnimation *pAnimation);

    CC_SYNTHESIZE_RETAIN(CCAnimation*, m_pAnimation, Animation)

protected:

    std::vector<float>* m_pSplitTimes;

    int                m_nNextFrame;

    CCSpriteFrame*  m_pOrigFrame;

       unsigned int    m_uExecutedLoops;

};


/** Overrides the target of an action so that it always runs on the target

 * specified at action creation rather than the one specified by runAction.

 */

class CC_DLL CCTargetedAction : public CCActionInterval 

//本身含target的动作 target可以随意设置而非调用动作的node

{

public:

    CCTargetedAction();

    virtual ~CCTargetedAction();


    /** Create an action with the specified action and forced target */

    static CCTargetedAction* create(CCNode* pTarget, CCFiniteTimeAction* pAction);


    /** Init an action with the specified action and forced target */

    bool initWithTarget(CCNode* pTarget, CCFiniteTimeAction* pAction);


    virtual CCObject* copyWithZone(CCZone* pZone);

    virtual void startWithTarget(CCNode *pTarget);

    virtual void stop(void);

    virtual void update(float time);


    /** This is the target that the action will be forced to run with */

    CC_SYNTHESIZE_RETAIN(CCNode*, m_pForcedTarget, ForcedTarget);

private:

    CCFiniteTimeAction* m_pAction;

};


// end of actions group

/// @}


NS_CC_END


#endif //__ACTION_CCINTERVAL_ACTION_H__


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值