想通过分析cocos2d-x的源码,加深对cocos的理解,当然,主要是查看cocos的API和对API的一些翻译。
Action源码注释:
/**
* @brief Base class for Action objects.
*@biref 动作类的基类,继承自Ref和Clonable,说明这个基类能放在自动回收池中,同时,能够被克隆。
*/
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.
*返回动作的一个副本
* @return A clone action.
*/
virtual Action* clone() const
{
CC_ASSERT(0);
return nullptr;
}
/** Returns a new action that performs the exactly the reverse action.
*返回一个新动作,这个动作执行的是完全相反的动作
* @return A new action that performs the exactly the reverse action.
* @js NA
*/
virtual Action* reverse() const
{
CC_ASSERT(0);
return nullptr;
}
/** Return true if the action has finished.
* 如果动作已经结束,则返回true
* @return Is true if the action has finished.
*/
virtual bool isDone() const;
/** Called before the action start. It will also set the target.
*在动作开始之前调用,同时也设置动作的标签
* @param target A certain target.
*/
virtual void startWithTarget(Node *target);
/**
* Called after the action has finished. It will set the 'target' to nil.
*在动作结束后调用,同时设置动作的标签为nil(null)
* IMPORTANT: You should never call "Action::stop()" manually. Instead, use: "target->stopAction(action);".
*警告:你永远不应该手动的调用Action::stop(),用target->stopAction(action)来代替
*/
virtual void stop();
/** Called every frame with it's delta time, dt in seconds. DON'T override unless you know what you are doing.
*在他的时间变量之间每帧调用,不要重载,除非你知道你在干什么。
* @param dt In seconds.
*/
virtual void step(float dt);
/**
* Called once per frame. time a value between 0 and 1.
*每帧调用一次,时间是0-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.
*-0代表动作刚开始
*0.5代表动作进行了一半了
*-1代表动作已经结束
* @param time A value between 0 and 1.
*/
virtual void update(float time);
/** Return certain target.
*返回一个确切的标签
* @return A certain target.
*/
inline Node* getTarget() const { return _target; }
/** The action will modify the target properties.
*这个动作将会修改标签属性
* @param target A certain target.
*/
inline void setTarget(Node *target) { _target = target; }
/** Return a original Target.
*返回一个原始的标签
* @return A original Target.
*/
inline Node* getOriginalTarget() const { return _originalTarget; }
/**
* Set the original target, since target can be nil.
*设置原始目标,因为目标可以是nil(0)
* Is the target that were used to run the action. Unless you are doing something complex, like ActionManager, you should NOT call this method.
*这个标签使用了运行动作的,除非你在做一些复合,比如 ActionManager,否则,你不应该调用这个方法。
* The target is 'assigned', it is not 'retained'.这个标签是给定的,不是保持的。
* @since v0.8.2
*
* @param originalTarget Is 'assigned', it is not 'retained'.
*/
inline void setOriginalTarget(Node *originalTarget) { _originalTarget = originalTarget; }
/** Returns a tag that is used to identify the action easily.
*返回一个易于识别动作的标签
* @return A tag.
*/
inline int getTag() const { return _tag; }
/** Changes the tag that is used to identify the action easily.
*改变那个易于识别动作的标签
* @param tag Used to identify the action easily.
*/
inline void setTag(int tag) { _tag = tag; }
CC_CONSTRUCTOR_ACCESS:
Action();
virtual ~Action();
protected:
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'.
*/
/// target 在startWithTarget方法中设置,当调用stop方法的时候,target会被设置为nil
/// 这个target是指定的,而不是保持的
Node *_target;
/** The action tag. An identifier of the action. */
/// 动作的标签,一个动作的标识
int _tag;
private:
CC_DISALLOW_COPY_AND_ASSIGN(Action);
};