您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
/** @brief Base class for Action objects. */ 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 */ virtual Action* clone() const = 0; /** returns a new action that performs the exactly the reverse action */ virtual Action* reverse() const = 0; //! return true if the action has finished 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(); //! called every frame with it's delta time. DON'T override unless you know what you are doing. virtual void step(float dt); /** called once per frame. time a value between 0 and 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 */ virtual void update(float time); inline Node* getTarget() const { return _target; } /** The action will modify the target properties. */ inline void setTarget(Node *target) { _target = target; } inline Node* getOriginalTarget() const { return _originalTarget; } /** Set the original target, since target can be nil. Is the target that were used to run the action. Unless you are doing something complex, like ActionManager, you should NOT call this method. The target is 'assigned', it is not 'retained'. @since v0.8.2 */ inline void setOriginalTarget(Node *originalTarget) { _originalTarget = originalTarget; } inline int getTag() const { return _tag; } inline void setTag(int tag) { _tag = tag; } protected: Action(); virtual ~Action(); 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'. */ Node *_target; /** The action tag. An identifier of the action */ int _tag; private: CC_DISALLOW_COPY_AND_ASSIGN(Action); };
virtual void startWithTarget(Node *target) override; void ActionInterval::startWithTarget(Node *target) { FiniteTimeAction::startWithTarget(target); _elapsed = 0.0f; _firstTick = true; }
void ActionInterval::step(float dt) { if (_firstTick) { _firstTick = false; _elapsed = 0; } else { _elapsed += dt; } this->update(MAX (0, // needed for rewind. elapsed could be negative MIN(1, _elapsed / MAX(_duration, FLT_EPSILON) // division by 0 ) ) ); }
void RotateTo::update(float time) { if (_target) { _target->setRotationSkewX(_startAngleX + _diffAngleX * time); _target->setRotationSkewY(_startAngleY + _diffAngleY * time); } }
virtual bool isDone(void) const override; bool ActionInterval::isDone(void) const { return _elapsed >= _duration; }
// action manager //动作管理器 _actionManager = new ActionManager(); _scheduler->scheduleUpdate(_actionManager, Scheduler::PRIORITY_SYSTEM, false);
// main loop void ActionManager::update(float dt) { //枚举动作表中的每一个目标节点 for (tHashElement *elt = _targets; elt != nullptr; ) { _currentTarget = elt; _currentTargetSalvaged = false; if (! _currentTarget->paused) { // The 'actions' MutableArray may change while inside this loop. //枚举目标节点对应的每一个动作 //actions 数组可能会在循环中被修改,因此需要谨慎处理 for (_currentTarget->actionIndex = 0; _currentTarget->actionIndex < _currentTarget->actions->num; _currentTarget->actionIndex++) { _currentTarget->currentAction = (Action*)_currentTarget->actions->arr[_currentTarget->actionIndex]; if (_currentTarget->currentAction == nullptr) { continue; } _currentTarget->currentActionSalvaged = false; //触发动作更新 _currentTarget->currentAction->step(dt); if (_currentTarget->currentActionSalvaged) { // The currentAction told the node to remove it. To prevent the action from // accidentally deallocating itself before finishing its step, we retained // it. Now that step is done, it's safe to release it. _currentTarget->currentAction->release(); } else if (_currentTarget->currentAction->isDone()) { _currentTarget->currentAction->stop(); Action *action = _currentTarget->currentAction; // Make currentAction nil to prevent removeAction from salvaging it. _currentTarget->currentAction = nullptr; removeAction(action); } _currentTarget->currentAction = nullptr; } } // elt, at this moment, is still valid // so it is safe to ask this here (issue #490) elt = (tHashElement*)(elt->hh.next); // only delete currentTarget if no actions were scheduled during the cycle (issue #481) if (_currentTargetSalvaged && _currentTarget->actions->num == 0) { deleteHashElement(_currentTarget); } } // issue #635 _currentTarget = nullptr; }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。