CCLayer註冊lua回呼函數setTouchPriority失效,lua回呼函數
CCLayer註冊lua回呼函數setTouchPriority失效:方式1、不行 touchLayer:setTouchPriority(-5000) touchLayer:registerScriptTouchHandler(touchLayerCallFunc) touchLayer:setTouchEnabled(true) maskLayer:addChild(touchLayer) 方式2、可以touchLayer:registerScriptTouchHandler(touchLayerCallFunc, false, -5000, true)touchLayer:setTouchEnabled(true)maskLayer:addChild(touchLayer)原因:void CCLayer::registerWithTouchDispatcher(){ CCTouchDispatcher* pDispatcher = CCDirector::sharedDirector()->getTouchDispatcher(); // Using LuaBindings /* 我們使用registerScriptTouchHandler方法註冊了回調,所以m_pScriptTouchHandlerEntry不為空白: void CCLayer::registerScriptTouchHandler(int nHandler, bool bIsMultiTouches, int nPriority, bool bSwallowsTouches){ unregisterScriptTouchHandler(); m_pScriptTouchHandlerEntry = CCTouchScriptHandlerEntry::create(nHandler, bIsMultiTouches, nPriority, bSwallowsTouches); m_pScriptTouchHandlerEntry->retain();} */ if (m_pScriptTouchHandlerEntry) { if (m_pScriptTouchHandlerEntry->isMultiTouches()) //多點觸摸 { pDispatcher->addStandardDelegate(this, 0); LUALOG("[LUA] Add multi-touches event handler: %d", m_pScriptTouchHandlerEntry->getHandler()); } else //單點觸摸 { //注意這裡和C++的不同,這個的優先順序和是否吞噬,都是CCTouchScriptHandlerEntry類中的成員變數, //也就是我們調用registerScriptTouchHandler方法傳進來的值,而不是通過setTouchPriority方法設定 //的m_nTouchPriority成員變數,這個變數對於lua沒用。 pDispatcher->addTargetedDelegate(this,m_pScriptTouchHandlerEntry->getPriority(),m_pScriptTouchHandlerEntry->getSwallowsTouches()); LUALOG("[LUA] Add touch event handler: %d", m_pScriptTouchHandlerEntry->getHandler()); } } else { if( m_eTouchMode == kCCTouchesAllAtOnce ) { pDispatcher->addStandardDelegate(this, 0); } else { //C++中調用優先順序才會用到m_nTouchPriority變數,即可以通過setTouchPriority方法設定。 pDispatcher->addTargetedDelegate(this, m_nTouchPriority, true); } }}