Cocos2d-x 监听 Action finish

来源:互联网 发布:c语言平方根怎么表示 编辑:程序博客网 时间:2024/06/05 06:35

cocos2d-x的Action自身没有提供动画结束的监听逻辑,而是虚拟一个Action和目标action一起组合到Sequence Action中,让虚拟的Action也就是最后一个Action被执行update的时候,进行回调处理。这个虚拟的Action定义如下:


class CC_DLL CallFunc : public ActionInstant //<NSCopying>{public:    /** Creates the action with the callback of type std::function<void()>.     This is the preferred way to create the callback.     * When this funtion bound in js or lua ,the input param will be changed.     * In js: var create(var func, var this, var [data]) or var create(var func).     * In lua:local create(local funcID).     *     * @param func  A callback function need to be excuted.     * @return  An autoreleased CallFunc object.     */    static CallFunc * create(const std::function<void()>& func);    /** Creates the action with the callback     typedef void (Ref::*SEL_CallFunc)();     @deprecated Use the std::function API instead.     * @js NA     * @lua NA     */    CC_DEPRECATED_ATTRIBUTE static CallFunc * create(Ref* target, SEL_CallFunc selector);
可见CallFunc继承了ActionInstant,所以CallFunc对于Sequence,ActionManager来说都是普通的Action不需要做特殊操作,也没有什么额外的耦合。

感觉这个地方有点别扭,CallFunc命名完全看不出来跟Action done callback有什么关系,而且这个使用的条件是要通过Sequence Action组合,在Sequence那边也完全没有什么联系,action done 为什么要依赖Sequence呢,想不明白

0 0
原创粉丝点击