在runAction中一个CallFuncN中的Node参数传入时机

时间:2022-01-24 21:22:18


-- 间隔一段时间播放一次动画(比如扫光)
function UI.nodePlayIntervalAnimation( node, uiname, time )
time = time or 5

UI.setVisible( node, true )
node:runAction( cc.RepeatForever:create( cc.Sequence:create(
cc.CallFunc:create(
function( target ) --1.这个target参数如何传进来?
target:stopAllActions()
local action = UI.createTimeline( uiname )
target:runAction( action )
action:gotoFrameAndPlay( 0, false )
end ),
cc.DelayTime:create( time ) ) ) )
end




class CC_DLL ActionInstant : public FiniteTimeAction //<NSCopying>
{
...
};



class CC_DLL FiniteTimeAction : public Action
{
...
};


CallFuncN * CallFuncN::create(const std::function<void(Node*)> &func)
{
auto ret = new (std::nothrow) CallFuncN();

if (ret && ret->initWithFunction(func) ) {
ret->autorelease();
return ret;
}

CC_SAFE_DELETE(ret);
return nullptr;
}


bool CallFuncN::initWithFunction(const std::function<void (Node *)> &func)
{
_functionN = func;
return true;
}


void CallFuncN::execute() {
if (_callFuncN) {
(_selectorTarget->*_callFuncN)(_target);
}
else if (_functionN) { --2.最后会执行这个
_functionN(_target);
}
}


Action * Node::runAction(Action* action)
{
CCASSERT( action != nullptr, "Argument must be non-nil");
_actionManager->addAction(action, this, !_running); --3.在这添加到里表中
return action;
}


void ActionManager::addAction(Action *action, Node *target, bool paused)
{
CCASSERT(action != nullptr, "action can't be nullptr!");
CCASSERT(target != nullptr, "target can't be nullptr!");

tHashElement *element = nullptr;
// we should convert it to Ref*, because we save it as Ref*
Ref *tmp = target;
HASH_FIND_PTR(_targets, &tmp, element);
if (! element)
{
element = (tHashElement*)calloc(sizeof(*element), 1);
element->paused = paused;
target->retain();
element->target = target;
HASH_ADD_PTR(_targets, target, element);
}

actionAllocWithHashElement(element);

CCASSERT(! ccArrayContainsObject(element->actions, action), "action already be added!");
ccArrayAppendObject(element->actions, action);

action->startWithTarget(target); --4.在这关联起来target
}


void Action::startWithTarget(Node *aTarget)
{
_originalTarget = _target = aTarget;
}