Forum Libraries, Components, and Plugins

Calling .RemoveAllListeners() on any child CCNode stops all listeners in the current CCScene

Hi everyone :)
Found out today that calling .RemoveAllListeners() on any child CCNode on WP8 stops all listeners in the current CCScene.
Not sure if this is a bug or feature.

https://github.com/mono/CocosSharp/blob/9acce26322ced620099a5a8e7aa2e8546da5db9b/src/base_nodes/CCNode.cs#L812

https://github.com/mono/CocosSharp/blob/9acce26322ced620099a5a8e7aa2e8546da5db9b/src/base_nodes/CCNode.cs#L1838

The goal of this method was not clear until I saw source code.

Thanks!

Tagged:

Posts

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    Alex

    Yes as it says it removes all listeners and is a convenience method so that the developer does not have to keep track of all listeners and remove them one by one.

        /// <summary>
        /// Removes all listeners
        /// </summary>
        public void RemoveAllListeners()
        {
        }
    

    If you want to remove listeners from a specific node call:

        /// <summary>
        /// Removes all listeners which are associated with this node.
        /// </summary>
        /// <param name="recursive"></param>
        public void RemoveEventListeners(bool recursive = false)
        {
            RemoveEventListeners(this, recursive);
        }
    

    Or use the following to remove the event listeners targeting a specific node.:

        /// <summary>
        /// Removes all listeners which are associated with the specified target.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="recursive"></param>
        public void RemoveEventListeners(CCNode target, bool recursive = false)
        {
    
        }
    

    To remove all the instances of a specific event listener use the following convenience method passing in the event listener type to be removed.:

        /// <summary>
        /// Removes all listeners with the same event listener type
        /// </summary>
        /// <param name="listenerType"></param>
        public void RemoveEventListeners(CCEventListenerType listenerType)
        {
        }
    

    To remove a specific listener

        /// <summary>
        /// Remove a listener
        /// </summary>
        /// <param name="listener">The specified event listener which needs to be removed.</param>
        public void RemoveEventListener(CCEventListener listener)
        {
    
        }
    

    I do believe there are examples of all of these being used in the EventDispatcherTests.

  • AlexSAlexS USUniversity ✭✭✭

    Thank you, the method name was misleading for me.
    Your answer is correct.

Sign In or Register to comment.