cocos2d-x-3.3rc2 动作管理 ActionManager

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

    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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值