diff --git a/cocos2dx/event_dispatcher/CCEventDispatcher.cpp b/cocos2dx/event_dispatcher/CCEventDispatcher.cpp index 9a4d8133da..1eef719a76 100644 --- a/cocos2dx/event_dispatcher/CCEventDispatcher.cpp +++ b/cocos2dx/event_dispatcher/CCEventDispatcher.cpp @@ -30,6 +30,9 @@ #include + +#define DUMP_LISTENER_ITEM_PRIORITY_INFO 0 + namespace { @@ -55,7 +58,6 @@ private: NS_CC_BEGIN - EventDispatcher::EventDispatcher() : _inDispatch(0) , _listeners(nullptr) @@ -497,10 +499,11 @@ void EventDispatcher::sortAllEventListenerItemsForType(const std::string &eventT // After sort: priority < 0, = 0, scene graph, > 0 std::sort(listenerList->begin(), listenerList->end(), [](const EventListenerItem* item1, const EventListenerItem* item2) { + // item1 and item2 are both using fixed priority. if (nullptr == item1->node && nullptr == item2->node) { - return item1->fixedPriority > item2->fixedPriority; + return item1->fixedPriority < item2->fixedPriority; } // item1 and item2 are both using scene graph based priority. else if (nullptr != item1->node && nullptr != item2->node) @@ -513,7 +516,7 @@ void EventDispatcher::sortAllEventListenerItemsForType(const std::string &eventT } else if (nullptr == item1->node && nullptr != item2->node) { - return item1->fixedPriority < 0; + return item1->fixedPriority <= 0; } else { @@ -521,6 +524,15 @@ void EventDispatcher::sortAllEventListenerItemsForType(const std::string &eventT return false; } }); + +#if DUMP_LISTENER_ITEM_PRIORITY_INFO + log("-----------------------------------"); + for (auto& item : *listenerList) + { + log("listener item priority: node (%p), fixed (%d)", item->node, item->fixedPriority); + } +#endif + } std::vector* EventDispatcher::getListenerItemsForType(const std::string &eventType)