緩沖動作:這些動作的執行的時間間隔是不斷變化的,大部分分為三種形式In(先快後慢),Out(先慢後快),InOut(先快後慢再快)
源檔案中有許多動作的實作,就不一一的分析了,将這類動作進行了一個整體的分類和分析。按着自己的了解分了下類。
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIyVGduV2QvwVe0lmdhJ3ZvwFM38CXlZHbvN3cpR2Lc1TPB10QGtWUCpEMJ9CXsxWam9CXwADNvwVZ6l2c052bm9CXUJDT1wkNhVzLcRnbvZ2LcZXUYpVd1kmYr50MZV3YyI2cKJDT29GRjBjUIF2LcRHelR3LcJzLctmch1mclRXY39jNxEDO1YzMzIDMygDM1EDMy8CX0Vmbu4GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.jpg)
用的最多的就是最普通的三種形式來,至于後面的,根據各種函數來執行的,其實我是沒用到過,可能是研究的不夠深入,看官方的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);
};