time:2015/05/14
void Node ::pause () { _scheduler-> pauseTarget(this ); _actionManager-> pauseTarget(this ); _eventDispatcher-> pauseEventListenersForTarget(this ); }
分析:
for k, v in pairs(layer:getChildren()) do v:pause() end
2. Lua的pause函数为什么没有起作用?
--test page@2015/04/15 : pause local moveBy = cc.MoveBy:create(2, cc.p(100, 0)) local actionMove = cc.Sequence:create(moveBy, moveBy:reverse()); layer:runAction(cc.RepeatForever:create(actionMove)) local btnPause = cc.MenuItemImage:create("Images/pauseBtn.png","Images/pauseBtn.png"); btnPause:setScale(3) local bPaused = false; local call = function(sender) if not bPaused then bPaused = true; layer:pause(); print("pause ... ") else bPaused = false; layer:resume(); print("resume ... ") end end -- btnPause:addTouchEventListener(call) btnPause:registerScriptTapHandler(call) local menu = cc.Menu:create() menu:setPosition(cc.p(0, 0)) menu:addChild(btnPause) layer:addChild(menu) --schedule -- local fnActionPause = function(dt) layer.fnActionPause = function(dt) print("fnActionPause ... ", dt) local sprite = cc.Sprite:create("Images/CyanTriangle.png") local act = cc.DelayTime:create(2) layer:addChild(sprite) sprite:setPosition(VisibleRect:center()) local callRemove = function() sprite:removeFromParent(true) end sprite:runAction(cc.Sequence:create(act, cc.CallFunc:create(callRemove))) end local scheduler = cc.Director:getInstance():getScheduler(); _schedule = scheduler:scheduleScriptFunc(layer.fnActionPause, 3, false) --test end
4. lua和c++接口的区别
(1)c++
* c++增加定时器或者事件回调函数,不管是selector还是c++ 11中的std::function,都需要保存回调函数的类对象target
* 拿定时器来说Scheduler::schedule():会把事件加到类的成员变量_hashForTimers中,pauseTarget函数就会处理该结构
void Scheduler::schedule(const ccSchedulerFunc& callback, void *target, float interval, unsigned int repeat, float delay, bool paused, const std::string& key) { CCASSERT(target, "Argument target must be non-nullptr"); CCASSERT(!key.empty(), "key should not be empty!"); tHashTimerEntry *element = nullptr; HASH_FIND_PTR(_hashForTimers, &target, element); if (! element) { element = (tHashTimerEntry *)calloc(sizeof(*element), 1); element->target = target; HASH_ADD_PTR(_hashForTimers, target, element); // Is this the 1st element ? Then set the pause level to all the selectors of this target element->paused = paused; }
//下面的省略掉...
}
(2)lua
* lua添加事件的注册函数为Scheduler::scheduleScriptFunc
*会把事件回调函数以句柄的方式存放在另外一个结构:_scriptHandlerEntries中
* 结构_scriptHandlerEntries只有在Scheduler::update函数中同_hashForTimers一样的处理
*但是!没有pause函数会处理这个结构!!!--->所以理论上lua的事件是没有这个层级上的暂停的(paused=true);
总结
原文:http://www.cnblogs.com/pk-run/p/4441295.html