cocos2dx3.0 Action,FiniteTimeAction,Speed,Follow

来源:互联网 发布:广州数控铣床编程代码 编辑:程序博客网 时间:2024/04/29 08:14

class CC_DLL Action : public Ref, public Clonable{public:    /// Default tag used for all the actions    static const int INVALID_TAG = -1;    /**     * @js NA     * @lua NA     */    virtual std::string description() const;/** returns a clone of action *///克隆一个动作virtual Action* clone() const = 0;    /** returns a new action that performs the exactly the reverse action *///克隆一个相反的动作virtual Action* reverse() const = 0;    //! return true if the action has finished//动作是否结束,动作结束时,该动作计数为0,接着就被自动删除,要retain一下才能看是否结束    virtual bool isDone() const;    //! called before the action start. It will also set the target.//在开始动作前别调用    virtual void startWithTarget(Node *target);    /**     called after the action has finished. It will set the 'target' to nil.    IMPORTANT: You should never call "[action stop]" manually. Instead, use: "target->stopAction(action);"    *///停止动作    virtual void stop();    //! called every frame with it's delta time. DON'T override unless you know what you are doing.//每步都会调用    virtual void step(float dt);    /**     called once per frame. time a value between 0 and 1    For example:     - 0 means that the action just started    - 0.5 means that the action is in the middle    - 1 means that the action is over    */    virtual void update(float time);    //得到目标    inline Node* getTarget() const { return _target; }    /** The action will modify the target properties. */    inline void setTarget(Node *target) { _target = target; }        inline Node* getOriginalTarget() const { return _originalTarget; }    /** Set the original target, since target can be nil.    Is the target that were used to run the action. Unless you are doing something complex, like ActionManager, you should NOT call this method.    The target is 'assigned', it is not 'retained'.    @since v0.8.2    */    inline void setOriginalTarget(Node *originalTarget) { _originalTarget = originalTarget; }//得到和设置标签    inline int getTag() const { return _tag; }    inline void setTag(int tag) { _tag = tag; }protected:    Action();    virtual ~Action();    Node    *_originalTarget;    /** The "target".    The target will be set with the 'startWithTarget' method.    When the 'stop' method is called, target will be set to nil.    The target is 'assigned', it is not 'retained'.    */    Node    *_target;    /** The action tag. An identifier of the action */    int     _tag;private:    CC_DISALLOW_COPY_AND_ASSIGN(Action);};/** @brief  Base class actions that do have a finite time duration. Possible actions:   - An action with a duration of 0 seconds   - An action with a duration of 35.5 seconds Infinite time actions are valid *///有限时间动作class CC_DLL FiniteTimeAction : public Action{public:    //! get duration in seconds of the action//得到持续时间    inline float getDuration() const { return _duration; }    //! set duration in seconds of the action//设置持续时间    inline void setDuration(float duration) { _duration = duration; }    //    // Overrides    //    virtual FiniteTimeAction* reverse() const override = 0;virtual FiniteTimeAction* clone() const override = 0;protected:    FiniteTimeAction(): _duration(0)    {}    virtual ~FiniteTimeAction(){}    //! duration in seconds    float _duration;private:    CC_DISALLOW_COPY_AND_ASSIGN(FiniteTimeAction);};class ActionInterval;class RepeatForever;/**  @brief Changes the speed of an action, making it take longer (speed>1) or less (speed<1) time. Useful to simulate 'slow motion' or 'fast forward' effect. @warning This action can't be Sequenceable because it is not an IntervalAction *///按速度动作class CC_DLL Speed : public Action{public:    /** create the action *///创建一个速度动作,第一个参数为限时动画,第二个参数为播放速度    static Speed* create(ActionInterval* action, float speed);//得到速度    inline float getSpeed(void) const { return _speed; }    /** alter the speed of the inner function in runtime *///设置速度    inline void setSpeed(float speed) { _speed = speed; }//设置内部的限时速度    void setInnerAction(ActionInterval *action);//得到限时速度    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() const  override;    CC_CONSTRUCTOR_ACCESS:    Speed();    virtual ~Speed(void);    /** initializes the action */    bool initWithAction(ActionInterval *action, float speed);protected:    float _speed;    ActionInterval *_innerAction;private:    CC_DISALLOW_COPY_AND_ASSIGN(Speed);};/** @brief Follow is an action that "follows" a node.Eg:@codelayer->runAction(Follow::actionWithTarget(hero));@endcodeInstead of using Camera as a "follower", use this action instead.@since v0.99.2*///对象跟着物体动class CC_DLL Follow : public Action{public:    /**     * Creates the action with a set boundary or with no boundary.     *     * @param followedNode  The node to be followed.     * @param rect  The boundary. If \p rect is equal to Rect::ZERO, it'll work     *              with no boundary.     */    static Follow* create(Node *followedNode, const Rect& rect = Rect::ZERO);    inline bool isBoundarySet() const { return _boundarySet; }    /** alter behavior - turn on/off boundary *///边界设置是否开启    inline void setBoudarySet(bool value) { _boundarySet = value; }    //    // Override    //virtual Follow* clone() const override;virtual Follow* reverse() const override;    virtual void step(float dt) override;    virtual bool isDone() const override;    virtual void stop() override;CC_CONSTRUCTOR_ACCESS:    /**     * @js ctor     */    Follow()    : _followedNode(nullptr)    , _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();        /**     * Initializes the action with a set boundary or with no boundary.     *     * @param followedNode  The node to be followed.     * @param rect  The boundary. If \p rect is equal to Rect::ZERO, it'll work     *              with no boundary.     */    bool initWithTarget(Node *followedNode, const Rect& rect = Rect::ZERO);protected:    // node to follow    Node *_followedNode;    // whether camera should be limited to certain area    bool _boundarySet;    // if screen size is bigger than the boundary - update not needed    bool _boundaryFullyCovered;    // fast access to the screen dimensions    Point _halfScreenSize;    Point _fullScreenSize;    // world boundaries    float _leftBoundary;    float _rightBoundary;    float _topBoundary;    float _bottomBoundary;Rect _worldRect;private:    CC_DISALLOW_COPY_AND_ASSIGN(Follow);};


0 0
原创粉丝点击