cococococococos 2 d-Xノード(CCAction.h)API


本論文はhttp://blog.csdn.net/runaying ,引用は出典を明記しなければならない!
cococococococos 2 d-Xノード(CCAction.h)API
みなさんがよりよく勉強できるように、私のブログを見ることを強くおすすめします。 Cocos 2 d-X権威ガイドノート
///cocos2d-x-3.0alpha0/cocos2dx/actions


#ifndef __ACTIONS_CCACTION_H__
#define __ACTIONS_CCACTION_H__

#include "cocoa/CCObject.h"
#include "cocoa/CCGeometry.h"
#include "platform/CCPlatformMacros.h"

NS_CC_BEGIN

/**
 * @addtogroup actions
 * @{
 */

/** 
@brief  Action       .
 */
class CC_DLL Action : public Object, public Clonable
{
public:
    ///    action        
    static const int INVALID_TAG = -1;
    /**
     * @js ctor
     */
    Action(void);
    /**
     * @js NA
     * @lua NA
     */
    virtual ~Action(void);
    /**
     * @js NA
     * @lua NA
     */
    const char* description() const;

	/** returns       action */
	virtual Action* clone() const = 0;

    /** returns      action           */
	virtual Action* reverse() const = 0;

    //! return true    action    
    virtual bool isDone(void) const;

    //!      .       target.
    virtual void startWithTarget(Node *target);

    /** 
    action     .      'target'   nil.
    IMPORTANT:             "[action stop]" .     : "target->stopAction(action);  "
    */
    virtual void stop(void);

    //!            ,                 .
    virtual void step(float dt);

    /** 
           .      0   1   

    For example: 
    - 0     action     
    - 0.5     action      
    - 1     action     
    */
    virtual void update(float time);
    
    inline Node* getTarget(void) const { return _target; }
    /**   action    target   . */
    inline void setTarget(Node *target) { _target = target; }
    
    inline Node* getOriginalTarget(void) const { return _originalTarget; }
    /** target   nil        target
       target          action,            ,     action             
    target    'assigned'(  ),       'retained'(  ).
    @since v0.8.2
    */
    inline void setOriginalTarget(Node *pOriginalTarget) { _originalTarget = pOriginalTarget; }

    inline int getTag(void) const { return _tag; }
    inline void setTag(int nTag) { _tag = nTag; }

protected:
    Node    *_originalTarget;
    /** The "target".
    target     'startWithTarget'     .
     'stop'      , target      nil.
   target    'assigned'(  ),       'retained'(  ).
    */
    Node    *_target;
    /**  action   .  action       */
    int     _tag;
};

/** 
@brief 
 action     ,             
 Possible actions:
   -            0  
   -            35.5  

             
 */
class CC_DLL FiniteTimeAction : public Action
{
public:
    /**
     * @js ctor
     */
    FiniteTimeAction()
	: _duration(0)
    {}
    /**
     * @js NA
     * @lua NA
     */
    virtual ~FiniteTimeAction(){}
    //! get    action      ( )
    inline float getDuration(void) const { return _duration; }
    //! set    action      ( )
    inline void setDuration(float duration) { _duration = duration; }

    //
    // Overrides
    //
    virtual FiniteTimeAction* reverse() const override = 0;
	virtual FiniteTimeAction* clone() const override = 0;

protected:
    //!    ( )
    float _duration;
};

class ActionInterval;
class RepeatForever;

/** 
 @brief       action, m          (speed>1)
 or less (speed<1) time.
    'slow motion'(   ) or 'fast forward'(  )          .
 @warning    action   Sequenceable(    )         IntervalAction(   actton)
 */
class CC_DLL Speed : public Action
{
public:
    /** create the action */
    static Speed* create(ActionInterval* pAction, float fSpeed);
    /**
     * @js ctor
     */
    Speed();
    /**
     * @js NA
     * @lua NA
     */
    virtual ~Speed(void);

    inline float getSpeed(void) const { return _speed; }
    /**          action   runtime(    ) */
    inline void setSpeed(float fSpeed) { _speed = fSpeed; }

    /**     action */
    bool initWithAction(ActionInterval *pAction, float fSpeed);

    void setInnerAction(ActionInterval *pAction);

    inline ActionInterval* getInnerAction() const { return _innerAction; }

    //
    // Override
    //
	virtual Speed* clone() const override;
    virtual Speed* reverse() const override;
    virtual void startWithTarget(Node* target) override;
    virtual void stop() override;
    virtual void step(float dt) override;
    virtual bool isDone(void) const  override;

protected:
    float _speed;
    ActionInterval *_innerAction;
};

/** 
@brief  action     ,       

Eg:
@code
layer->runAction(Follow::actionWithTarget(hero));
@endcode

     Camera          ,      action   .
@since v0.99.2
*/
class CC_DLL Follow : public Action
{
public:
    /**
     *               
     *
     * @param followedNode            
     * @param rect    .    rect  equal(  ) Rect::ZERO, i             
     */
    static Follow* create(Node *followedNode, const Rect& rect = Rect::ZERO);
    /**
     * @js ctor
     */
    Follow()
		: _followedNode(NULL)
        , _boundarySet(false)
        , _boundaryFullyCovered(false)        
        , _leftBoundary(0.0)
        , _rightBoundary(0.0)
        , _topBoundary(0.0)
        , _bottomBoundary(0.0)
		, _worldRect(Rect::ZERO)
    {}
    /**
     * @js NA
     * @lua NA
     */
    virtual ~Follow(void);
    
    inline bool isBoundarySet(void) const { return _boundarySet; }
    /**      -      /      */
    inline void setBoudarySet(bool bValue) { _boundarySet = bValue; }

    /**
     *                
     *
     * @param followedNode            
     * @param rect    .    rect  equal(  ) Rect::ZERO, i             
     */
    bool initWithTarget(Node *followedNode, const Rect& rect = Rect::ZERO);

    //
    // Override
    //
	virtual Follow* clone() const override;
	virtual Follow* reverse() const override;
    virtual void step(float dt) override;
    virtual bool isDone(void) const override;
    virtual void stop(void) override;

protected:
    //       node
    Node *_followedNode;

    //     camera(  )          
    bool _boundarySet;

    //    screen(  )        -      
    bool _boundaryFullyCovered;

    //      screen(  )   
    Point _halfScreenSize;
    Point _fullScreenSize;

    // world boundaries //   
    float _leftBoundary;
    float _rightBoundary;
    float _topBoundary;
    float _bottomBoundary;
	Rect _worldRect;

};

// end of actions group
/// @}

NS_CC_END

#endif // __ACTIONS_CCACTION_H__