一、Action

  1. class CC_DLL Action : public Ref, public Clonable
  2. {
  3. public:
  4. static const int INVALID_TAG = -1; // 默认tag
  5. virtual std::string description() const; // 一般用于日志
  6. virtual Action* cl3
  7. virtual Action* reverse() const; // 生成一个翻转action
  8. virtual bool isDone() const; // 知否执行完成
  9. // Called before the action start. It will also set the target.
  10. virtual void startWithTarget(Node *target);
  11. // Called after the action has finished. It will set the 'target' to nil.
  12. // IMPORTANT: You should never call "Action::stop()" manually. Instead, use: "target->stopAction(action);".
  13. virtual void stop();
  14. // Action的执行就在这里开始,dt表示距离上step的时间间隔。
  15. // Called every frame
  16. virtual void step(float dt);
  17. // 每个Action的实际执行逻辑,called once per frame,由step调用
  18. // time: 动画执行进度
  19. // - 0 Means that the action just started.
  20. // - 0.5 Means that the action is in the middle.
  21. // - 1 Means that the action is over.
  22. virtual void update(float time);
  23. Node* getTarget() const;
  24. // The action will modify the target properties.
  25. void setTarget(Node *target);
  26. // original Target
  27. Node* getOriginalTarget() const;
  28. void setOriginalTarget(Node *originalTarget);
  29. // identify action,注意这并不是唯一识别
  30. int getTag() const;
  31. void setTag(int tag);
  32. // flag field that is used to group the actions easily.
  33. unsigned int getFlags() const;
  34. void setFlags(unsigned int flags) { _flags = flags; }
  35. ......
  36. };

二、ActionManager

  1. class CC_DLL ActionManager : public Ref
  2. {
  3. public:
  4. // hash表存储action,桶bucket number与target一一对应,一个target一个桶
  5. // 插入对应桶中,桶不存在就创建
  6. // paused为false,action不会执行
  7. virtual void addAction(Action *action, Node *target, bool paused);
  8. // 清空hash表,如果是正在执行的target、action,则在执行完之后删除
  9. virtual void removeAllActions();
  10. // 清除target对应桶中的action,如果是正在执行的target、action,则在执行完之后删除
  11. virtual void removeAllActionsFromTarget(Node *target);
  12. // 删除指定action,如果是正在执行的target、action,则在执行完之后删除
  13. virtual void removeAction(Action *action);
  14. // tag: The action's tag.
  15. // 只会删除找到的第一个action
  16. virtual void removeActionByTag(int tag, Node *target);
  17. virtual void removeAllActionsByTag(int tag, Node *target);
  18. // Removes all actions matching at least one bit in flags and the target.
  19. virtual void removeActionsByFlags(unsigned int flags, Node *target);
  20. // 返回符合条件的第一个action
  21. virtual Action* getActionByTag(int tag, const Node *target) const;
  22. // 返回target桶中的action数量
  23. // Composable actions are counted as 1 action. Example:
  24. // - If you are running 1 Sequence of 7 actions, it will return 1.
  25. // - If you are running 7 Sequences of 2 actions, it will return 7.
  26. virtual ssize_t getNumberOfRunningActionsInTarget(const Node *target) const;
  27. // 返回所有target桶中的action数量之和
  28. virtual ssize_t getNumberOfRunningActions() const;
  29. // 返回target桶中指定tag的action数量
  30. virtual size_t getNumberOfRunningActionsInTargetByTag(const Node *target, int tag);
  31. // target桶中的所有action都会停止执行
  32. virtual void pauseTarget(Node *target);
  33. // 暂停所有action,并返回从!paused变paused的action
  34. virtual Vector<Node*> pauseAllRunningActions();
  35. virtual void resumeTarget(Node *target); // 恢复执行
  36. virtual void resumeTargets(const Vector<Node*>& targetsToResume);
  37. virtual void update(float dt); // 在这里执行所有动画
  38. ......
  39. };

三、Node

  1. class CC_DLL Node : public Ref {
  2. // 更换actionManager,默认是default action manager
  3. // 注意如果是new的,则之前的action全部被remove掉
  4. virtual void setActionManager(ActionManager* actionManager);
  5. virtual ActionManager* getActionManager();
  6. // 由当前的actionmanager执行。
  7. // Executes an action, and returns the action that is executed.
  8. // This node becomes the action's target. Refer to Action::getTarget().
  9. virtual Action* runAction(Action* action);
  10. // actionManager->removeAllActionsFromTarget();
  11. // stop and remove 当前节点作为target的所有action
  12. void stopAllActions();
  13. // stop and remove action
  14. // 先通过action->getOrignalTarget找到桶,再从桶中找到action去删除。
  15. // 注意,这里可以没有说action的target一定是当前node(this),而是通过getOrignalTarget获取
  16. void stopAction(Action* action);
  17. // 移除当前target桶中指定tag的action,只删除遇到的第一个。
  18. void stopActionByTag(int tag);
  19. // 同上,不同之处是删除所有指定tag的action
  20. void stopAllActionsByTag(int tag);
  21. // 删除满足以下条件的action
  22. // (action->getFlag() & flags) != 0 && action->getOrignalTarget() == this
  23. void stopActionsByFlags(unsigned int flags);
  24. // this桶中的指定tag的第一个action
  25. Action* getActionByTag(int tag);
  26. // Returns the numbers of actions that are running plus the ones
  27. // that are schedule to run (actions in actionsToAdd and actions arrays).
  28. // _actionManager->getNumberOfRunningActionsInTarget( this );
  29. ssize_t getNumberOfRunningActions() const;
  30. // actionManager->resumeTarget(this);
  31. void resumeSchedulerAndActions();
  32. // actionManager->pauseTarget(this);
  33. void pauseSchedulerAndActions();
  34. /**
  35. * Returns the numbers of actions that are running plus the ones that are
  36. * schedule to run (actions in actionsToAdd and actions arrays) with a
  37. * specific tag.
  38. *
  39. * Composable actions are counted as 1 action. Example:
  40. * If you are running 1 Sequence of 7 actions, it will return 1.
  41. * If you are running 7 Sequences of 2 actions, it will return 7.
  42. *
  43. * @param tag The tag that will be searched.
  44. *
  45. * @return The number of actions that are running plus the
  46. * ones that are schedule to run with specific tag.
  47. */
  48. ssize_t getNumberOfRunningActionsByTag(int tag) const;
  49. }