diff --git a/cocos2dx/event_dispatcher/CCEventDispatcher.cpp b/cocos2dx/event_dispatcher/CCEventDispatcher.cpp index 3ecaabe91c..a0a6880c67 100644 --- a/cocos2dx/event_dispatcher/CCEventDispatcher.cpp +++ b/cocos2dx/event_dispatcher/CCEventDispatcher.cpp @@ -217,12 +217,13 @@ void EventDispatcher::setPriorityWithFixedValue(EventListener* listener, int fix } } -void EventDispatcher::dispatchEvent(Event* event) +void EventDispatcher::dispatchEvent(Event* event, bool toSortListeners) { if (_listeners == nullptr || !_isEnabled) return; - sortAllEventListenerItemsForType(event->_type); + if (toSortListeners) + sortAllEventListenerItemsForType(event->_type); DispatchGuard guard(_inDispatch); diff --git a/cocos2dx/event_dispatcher/CCEventDispatcher.h b/cocos2dx/event_dispatcher/CCEventDispatcher.h index 8a1748da88..cb0cf75684 100644 --- a/cocos2dx/event_dispatcher/CCEventDispatcher.h +++ b/cocos2dx/event_dispatcher/CCEventDispatcher.h @@ -91,7 +91,7 @@ public: * Also removes all EventListeners marked for deletion from the * event dispatcher list. */ - void dispatchEvent(Event* event); + void dispatchEvent(Event* event, bool toSortListeners = true); public: /** Destructor of EventDispatcher */