CCAction文件中剩余类的分析:
1.FiniteTimeAction
源码:
/** @class FiniteTimeAction
* @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.
*/
/// 限时动作
/// 有时间限制的基本动作类。
/// 可能的动作:
/// -一个持续时间为0s的动作
/// -一个持续是将为35.5s的动作
/// 不限时动作是有效的。(这句不知道是不是应该这么翻译,总感觉,这样不太对,不理解这句话为什么放在这儿,有什么用??)
class CC_DLL FiniteTimeAction : public Action
{
public:
/** Get duration in seconds of the action.
*
* @return The duration in seconds of the action.
*/
/// 得到动作的持续时间,单位是秒
inline float getDuration() const { return _duration; }
/** Set duration in seconds of the action.
*
* @param duration In seconds of the action.
*/
/// 设置动作的持续时间,单位是秒,传入的参数也应该是以秒为单位的。
inline void setDuration(float duration) { _duration = duration; }
//
// Overrides
//
/// 这个在Action中有,产生一个相反的新动作
virtual FiniteTimeAction* reverse() const override
{
CC_ASSERT(0);
return nullptr;
}
/// 这个方法也是从Action中继承过来的,返回一个自身的拷贝
virtual FiniteTimeAction* clone() const override
{
CC_ASSERT(0);
return nullptr;
}
CC_CONSTRUCTOR_ACCESS:
FiniteTimeAction()
: _duration(0)
{}
virtual ~FiniteTimeAction(){}
protected:
//! Duration in seconds.
/// 持续时间,单位为秒
float _duration;
private:
CC_DISALLOW_COPY_AND_ASSIGN(FiniteTimeAction);
};
2.Speed
源码:
/** @class Speed
* @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.
*/
/// 速度
/// 改变动作的速度,使其花费的时间更长(speed>1的时候)或更短(speed < 1)
/// 可以用来模拟慢动作或者是快进的效果
/// 警告:这个动作是不能添加到序列动作中的,因为这个动作不是一个瞬时动作
class CC_DLL Speed : public Action
{
public:
/** Create the action and set the speed.
*
* @param action An action.
* @param speed The action speed.
*/
/// 产生一个动作,并且设置其速度
static Speed* create(ActionInterval* action, float speed);
/** Return the speed.
*
* @return The action speed.
*/
/// 返回动作的速度
inline float getSpeed(void) const { return _speed; }
/** Alter the speed of the inner function in runtime.
*
* @param speed Alter the speed of the inner function in runtime.
*/
/// 在动作运行时改变内部函数的速度
inline void setSpeed(float speed) { _speed = speed; }
/** Replace the interior action.
*
* @param action The new action, it will replace the running action.
*/
/// 代替内部的函数
void setInnerAction(ActionInterval *action);
/** Return the interior action.
*
* @return The interior action.
*/
/// 返回内部的函数
inline ActionInterval* getInnerAction() const { return _innerAction; }
//
// Override
//
virtual Speed* clone() const override;/// 动作的拷贝
virtual Speed* reverse() const override;/// 产生一个反向的新动作
virtual void startWithTarget(Node* target) override;/// 开始一个动作,并且设置target
virtual void stop() override;/// 停止一个动作,但是,不要手动调用,这个是对象自己调用的,如果,你想停止一个动作的话,调用stopAction吧
/**
* @param dt in seconds.
*/
virtual void step(float dt) override;
/** Return true if the action has finished.
*
* @return Is true if the action has finished.
*/
/// 返回动作是否已经结束
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);
};
3.Follow
源码:
/** @class Follow
* @brief Follow is an action that "follows" a node.
* Eg:
* @code
* layer->runAction(Follow::actionWithTarget(hero));
* @endcode
* Instead 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);
/** Return boundarySet.
*
* @return Return boundarySet.
*/
/// 摄像机是否被限定的固定的区域
inline bool isBoundarySet() const { return _boundarySet; }
/** Alter behavior - turn on/off boundary.
*
* @param value Turn on/off boundary.
*/
/// 改变行为,打开或关闭边界
inline void setBoundarySet(bool value) { _boundarySet = value; }
/** @deprecated Alter behavior - turn on/off boundary.
*
* @param value Turn on/off boundary.
*/
CC_DEPRECATED_ATTRIBUTE inline void setBoudarySet(bool value) { setBoundarySet(value); }
//
// Override
//
virtual Follow* clone() const override;
virtual Follow* reverse() const override;
/**
* @param dt in seconds.
* @js NA
*/
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. */
/// 快速进入屏幕的范围
Vec2 _halfScreenSize;// 半屏的尺寸
Vec2 _fullScreenSize;// 全屏的尺寸
/** World boundaries. */
/// 边界
float _leftBoundary;//左边界
float _rightBoundary;//右边界
float _topBoundary;//上边界
float _bottomBoundary;//下边界
Rect _worldRect;//世界矩形,限定的边界的矩形
private:
CC_DISALLOW_COPY_AND_ASSIGN(Follow);
};