cocos2d-x-3.3rc2 动作管理 ActionManager

来源:互联网 发布:印度对中国的看法 知乎 编辑:程序博客网 时间:2024/05/22 04:28

创建一个精灵 并指定动作 但动作并不执行 

    auto grossini = Sprite::create(s_pathGrossini);    addChild(grossini, 0, kTagGrossini);    grossini->setPosition(VisibleRect::center() );        auto action = MoveBy::create(1, Vec2(150,0));    auto director = Director::getInstance();    director->getActionManager()->addAction(action, grossini, true);     schedule( CC_SCHEDULE_SELECTOR(PauseTest::unpause), 3);  // 3秒后执行动作



通过导演下的动作管理可以恢复执行动作


void PauseTest::unpause(float dt){    unschedule( CC_SCHEDULE_SELECTOR(PauseTest::unpause) );    auto node = getChildByTag( kTagGrossini );    auto director = Director::getInstance();    director->getActionManager()->resumeTarget(node);}



不同的动作可以指定相同的tag

pRepeatMove->setTag(kTagSequence);

pRepeatScale->setTag(kTagSequence);


通过tag 停止所有此tag的动作。

sprite->stopAllActionsByTag(kTagSequence);



ActionManager 类

class CC_DLL ActionManager : public Ref{public:    /**     * @js ctor     */    ActionManager(void);    /**     * @js NA     * @lua NA     */    ~ActionManager(void);    // actions        /** Adds an action with a target.      If the target is already present, then the action will be added to the existing target.     If the target is not present, a new instance of this target will be created either paused or not, and the action will be added to the newly created target.     When the target is paused, the queued actions won't be 'ticked'.     */    void addAction(Action *action, Node *target, bool paused);<p>      //action   动作    //target   精灵    //paused   是否暂停</p>    /** Removes all actions from all the targets.    */    void removeAllActions();    /** Removes all actions from a certain target.     All the actions that belongs to the target will be removed.     */    void removeAllActionsFromTarget(Node *target);    /** Removes an action given an action reference.    */    void removeAction(Action *action);    /** Removes an action given its tag and the target */    void removeActionByTag(int tag, Node *target);        /** Removes all actions given its tag and the target */    void removeAllActionsByTag(int tag, Node *target);    /** Gets an action given its tag an a target     @return the Action the with the given tag     */    Action* getActionByTag(int tag, const Node *target) const;    /** Returns the numbers of actions that are running in a certain target.      * 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.     */    ssize_t getNumberOfRunningActionsInTarget(const Node *target) const;    /** @deprecated use getNumberOfRunningActionsInTarget() instead */    CC_DEPRECATED_ATTRIBUTE inline ssize_t numberOfRunningActionsInTarget(Node *target) const { return getNumberOfRunningActionsInTarget(target); }    /** Pauses the target: all running actions and newly added actions will be paused.    */    void pauseTarget(Node *target);    /** Resumes the target. All queued actions will be resumed.    */    void resumeTarget(Node *target);   ////恢复执行指定节点的动作        /** Pauses all running actions, returning a list of targets whose actions were paused.     */    Vector<Node*> pauseAllRunningActions();        /** Resume a set of targets (convenience function to reverse a pauseAllRunningActions call)     */    void resumeTargets(const Vector<Node*>& targetsToResume);    void update(float dt);    protected:    // declared in ActionManager.m    void removeActionAtIndex(ssize_t index, struct _hashElement *element);    void deleteHashElement(struct _hashElement *element);    void actionAllocWithHashElement(struct _hashElement *element);protected:    struct _hashElement    *_targets;    struct _hashElement    *_currentTarget;    bool            _currentTargetSalvaged;};







0 0