一、Action
class CC_DLL Action : public Ref, public Clonable{public: static const int INVALID_TAG = -1; // 默认tag virtual std::string description() const; // 一般用于日志 virtual Action* cl3 virtual Action* reverse() const; // 生成一个翻转action 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(); // Action的执行就在这里开始,dt表示距离上step的时间间隔。 // Called every frame virtual void step(float dt); // 每个Action的实际执行逻辑,called once per frame,由step调用 // time: 动画执行进度 // - 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); Node* getTarget() const; // The action will modify the target properties. void setTarget(Node *target); // original Target Node* getOriginalTarget() const; void setOriginalTarget(Node *originalTarget); // identify action,注意这并不是唯一识别 int getTag() const; void setTag(int tag); // flag field that is used to group the actions easily. unsigned int getFlags() const; void setFlags(unsigned int flags) { _flags = flags; } ......};
二、ActionManager
class CC_DLL ActionManager : public Ref{public: // hash表存储action,桶bucket number与target一一对应,一个target一个桶 // 插入对应桶中,桶不存在就创建 // paused为false,action不会执行 virtual void addAction(Action *action, Node *target, bool paused); // 清空hash表,如果是正在执行的target、action,则在执行完之后删除 virtual void removeAllActions(); // 清除target对应桶中的action,如果是正在执行的target、action,则在执行完之后删除 virtual void removeAllActionsFromTarget(Node *target); // 删除指定action,如果是正在执行的target、action,则在执行完之后删除 virtual void removeAction(Action *action); // tag: The action's tag. // 只会删除找到的第一个action virtual void removeActionByTag(int tag, Node *target); virtual void removeAllActionsByTag(int tag, Node *target); // Removes all actions matching at least one bit in flags and the target. virtual void removeActionsByFlags(unsigned int flags, Node *target); // 返回符合条件的第一个action virtual Action* getActionByTag(int tag, const Node *target) const; // 返回target桶中的action数量 // Composable actions are counted as 1 action. Example: // - If you are running 1 Sequence of 7 actions, it will return 1. // - If you are running 7 Sequences of 2 actions, it will return 7. virtual ssize_t getNumberOfRunningActionsInTarget(const Node *target) const; // 返回所有target桶中的action数量之和 virtual ssize_t getNumberOfRunningActions() const; // 返回target桶中指定tag的action数量 virtual size_t getNumberOfRunningActionsInTargetByTag(const Node *target, int tag); // target桶中的所有action都会停止执行 virtual void pauseTarget(Node *target); // 暂停所有action,并返回从!paused变paused的action virtual Vector<Node*> pauseAllRunningActions(); virtual void resumeTarget(Node *target); // 恢复执行 virtual void resumeTargets(const Vector<Node*>& targetsToResume); virtual void update(float dt); // 在这里执行所有动画 ......};
三、Node
class CC_DLL Node : public Ref { // 更换actionManager,默认是default action manager // 注意如果是new的,则之前的action全部被remove掉 virtual void setActionManager(ActionManager* actionManager); virtual ActionManager* getActionManager(); // 由当前的actionmanager执行。 // Executes an action, and returns the action that is executed. // This node becomes the action's target. Refer to Action::getTarget(). virtual Action* runAction(Action* action); // actionManager->removeAllActionsFromTarget(); // stop and remove 当前节点作为target的所有action void stopAllActions(); // stop and remove action // 先通过action->getOrignalTarget找到桶,再从桶中找到action去删除。 // 注意,这里可以没有说action的target一定是当前node(this),而是通过getOrignalTarget获取 void stopAction(Action* action); // 移除当前target桶中指定tag的action,只删除遇到的第一个。 void stopActionByTag(int tag); // 同上,不同之处是删除所有指定tag的action void stopAllActionsByTag(int tag); // 删除满足以下条件的action // (action->getFlag() & flags) != 0 && action->getOrignalTarget() == this void stopActionsByFlags(unsigned int flags); // this桶中的指定tag的第一个action Action* getActionByTag(int tag); // Returns the numbers of actions that are running plus the ones // that are schedule to run (actions in actionsToAdd and actions arrays). // _actionManager->getNumberOfRunningActionsInTarget( this ); ssize_t getNumberOfRunningActions() const; // actionManager->resumeTarget(this); void resumeSchedulerAndActions(); // actionManager->pauseTarget(this); void pauseSchedulerAndActions(); /** * Returns the numbers of actions that are running plus the ones that are * schedule to run (actions in actionsToAdd and actions arrays) with a * specific tag. * * Composable actions are counted as 1 action. Example: * If you are running 1 Sequence of 7 actions, it will return 1. * If you are running 7 Sequences of 2 actions, it will return 7. * * @param tag The tag that will be searched. * * @return The number of actions that are running plus the * ones that are schedule to run with specific tag. */ ssize_t getNumberOfRunningActionsByTag(int tag) const;}