您好,登錄后才能下訂單哦!
/** @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) { //枚舉動作表中的每一個目標(biāo)節(jié)點 for (tHashElement *elt = _targets; elt != nullptr; ) { _currentTarget = elt; _currentTargetSalvaged = false; if (! _currentTarget->paused) { // The 'actions' MutableArray may change while inside this loop. //枚舉目標(biāo)節(jié)點對應(yīng)的每一個動作 //actions 數(shù)組可能會在循環(huán)中被修改,因此需要謹(jǐn)慎處理 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; //觸發(fā)動作更新 _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; }
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。