cocos2dx 点击事件分析(4)

cocos2dx 点击事件分析(4),第1张

概述1、添加单点触摸事件,单点触摸事件有优先级,bSwallowsTouches是否吞噬,高优先级的会优先响应,而且可以吞噬事件,不让触摸事件往低优先级传递。void CCTouchDispatcher::addTargetedDelegate(CCTouchDelegate *pDelegate, int nPriority, bool bSwallowsTouches){
1、添加单点触摸事件,单点触摸事件有优先级,bSwallowstouches是否吞噬,高优先级的会优先响应,而且可以吞噬事件,不让触摸事件往低优先级传递。voID CCtouchdispatcher::addTargetedDelegate(CCtouchDelegate *pDelegate,int nPriority,bool bSwallowstouches){        CCtouchHandler *pHandler = CCTargetedtouchHandler::handlerWithDelegate(pDelegate,nPriority,bSwallowstouches);    if (! m_bLocked)    {        forceAddHandler(pHandler,m_pTargetedHandlers);    }    else    {        /* If pHandler is contained in m_pHandlersToRemove,if so remove it from m_pHandlersToRemove and return.         * Refer issue #752(cocos2d-x)         */        if (ccCArrayContainsValue(m_pHandlersToRemove,pDelegate))        {            ccCArrayRemoveValue(m_pHandlersToRemove,pDelegate);            return;        }        //CCArray* m_pHandlersToAdd这个可以理解为一个临时保存CCtouchHandler的地方,	//m_bLocked 如果这个值为true,这把CCtouchHandler先加入到m_pHandlersToAdd,	//然后在合适的时间,即CCtouchdispatcher::touches函数中,再把m_pHandlersToAdd数组里面	//CCtouchHandler加入到m_pTargetedHandlers或者m_pStandardHandlers中。        m_pHandlersToAdd->addobject(pHandler);        m_bToAdd = true;    }}-->>//// handlers management根据优先级进行排序,然后添加到单点触摸事件列表中,由此可知,//值越小,优先级越高//voID CCtouchdispatcher::forceAddHandler(CCtouchHandler *pHandler,CCArray *pArray){    unsigned int u = 0;    CCObject* pObj = NulL;    CCARRAY_FOREACH(pArray,pObj)     {         CCtouchHandler *h = (CCtouchHandler *)pObj;         if (h)         {             if (h->getPriority() < pHandler->getPriority())             {                 ++u;             }              if (h->getDelegate() == pHandler->getDelegate())             {                 CCAssert(0,"");                 return;             }         }     }    pArray->insertObject(pHandler,u);}2、移除:和加入类似voID CCtouchdispatcher::removeDelegate(CCtouchDelegate *pDelegate){    if (pDelegate == NulL)    {        return;    }    if (! m_bLocked)    {        forceRemoveDelegate(pDelegate);    }    else    {        /* If pHandler is contained in m_pHandlersToAdd,if so remove it from m_pHandlersToAdd and return.         * Refer issue #752(cocos2d-x)         */        CCtouchHandler *pHandler = findHandler(m_pHandlersToAdd,pDelegate);        if (pHandler)        {            m_pHandlersToAdd->removeObject(pHandler);            return;        }        ccCArrayAppendValue(m_pHandlersToRemove,pDelegate);        m_bToRemove = true;    }}-->>voID CCtouchdispatcher::removeDelegate(CCtouchDelegate *pDelegate){    if (pDelegate == NulL)    {        return;    }    if (! m_bLocked)    {        forceRemoveDelegate(pDelegate);    }    else    {        /* If pHandler is contained in m_pHandlersToAdd,pDelegate);        m_bToRemove = true;    }}
总结

以上是内存溢出为你收集整理的cocos2dx 点击事件分析(4)全部内容,希望文章能够帮你解决cocos2dx 点击事件分析(4)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1052142.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存