CCActionEase源码分析

缓冲动作:这些动作的执行的时间间隔是不断变化的,大部分分为三种形式In(先快后慢),Out(先慢后快),InOut(先快后慢再快)

源文件中有许多动作的实现,就不一一的分析了,将这类动作进行了一个整体的分类和分析。按着自己的理解分了下类。


用的最多的就是最普通的三种形式来,至于后面的,根据各种函数来执行的,其实我是没用到过,可能是研究的不够深入,看官方的Demo的话,也会发现,个别的动作,其实他们最后的效果差异也不是非常大。实现上的区别呢,就是update中参数的变化,当然,这些参数都是通过不同的数学公式计算出来的。可以不研究,但是,大部分都是高中数学中学过的函数。

只分析下基类的源码:

/** 
 @class ActionEase
 @brief Base class for Easing actions.
 @details Ease actions are created from other interval actions.
         The ease action will change the timeline of the inner action.
 @ingroup Actions
 */
 /// 缓冲动作
 /// 缓冲动作的基类
 /// 缓冲动作是通过其他瞬时动作创建的。
 /// 缓冲动作将改变动作内部的时间线。也就是,缓冲动作的时间是变化的。
 /// 缓冲动作是改变传入动作的执行速度
class CC_DLL ActionEase : public ActionInterval/// 继承自瞬时动作
{
public:

    /**
    @brief Get the pointer of the inner action.
    @return The pointer of the inner action.
    */
	/// 得到缓冲动作的内部动作
    virtual ActionInterval* getInnerAction();

    //
    // Overrides
    //
    virtual ActionEase* clone() const override
    {
        CC_ASSERT(0);
        return nullptr;
    }
    
    virtual ActionEase* reverse() const override
    {
        CC_ASSERT(0);
        return nullptr;
    }

    virtual void startWithTarget(Node *target) override;
    virtual void stop() override;
    virtual void update(float time) override;

CC_CONSTRUCTOR_ACCESS:
    ActionEase() {}
    virtual ~ActionEase();
    /** 
     @brief Initializes the action.
     @return Return true when the initialization success, otherwise return false.
    */
	/// 初始化
    bool initWithAction(ActionInterval *action);

protected:
    /** The inner action */
	/// 内部动作
    ActionInterval *_inner;
private:
    CC_DISALLOW_COPY_AND_ASSIGN(ActionEase);
};

/** 
 @class EaseRateAction
 @brief Base class for Easing actions with rate parameters.
 @details Ease the inner action with specified rate.
 @ingroup Actions
 */
 /// 指定比例的缓冲动作
 /// 根据指定的比例对内部动作执行缓冲动作
class CC_DLL EaseRateAction : public ActionEase
{
public:
    /**
     @brief Set the rate value for the ease rate action.
     @param rate The value will be set.
     */
	 /// 设置比例
    inline void setRate(float rate) { _rate = rate; }
    /**
     @brief Get the rate value of the ease rate action.
     @return Return the rate value of the ease rate action.
     */
	 /// 得到比例
    inline float getRate() const { return _rate; }

    //
    // Overrides
    //
    virtual EaseRateAction* clone() const override
    {
        CC_ASSERT(0);
        return nullptr;
    }
    virtual EaseRateAction* reverse() const override
    {
        CC_ASSERT(0);
        return nullptr;
    }

CC_CONSTRUCTOR_ACCESS:
    EaseRateAction() {}
    virtual ~EaseRateAction();
    /** 
     @brief Initializes the action with the inner action and the rate parameter.
     @param pAction The pointer of the inner action.
     @param fRate The value of the rate parameter.
     @return Return true when the initialization success, otherwise return false.
     */
	 /// 初始化
    bool initWithAction(ActionInterval *pAction, float fRate);

protected:
    float _rate;

private:
    CC_DISALLOW_COPY_AND_ASSIGN(EaseRateAction);
};


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值