CCLayer注册lua回调函数setTouchPriority失效

来源:互联网 发布:淘宝店招如何全屏 编辑:程序博客网 时间:2024/06/07 04:59
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);        }    }}

0 0