How to avoid propagation mouse events to other delegates (2.2.3)

Hi !
I’ve found this:

/**
 * <p> called when the "mouseMoved" event is received.            <br/>
 * Return YES to avoid propagating the event to other delegates.  </p>
 * @param {cc.Mouse} event
 * @return {Boolean}
 */
onMouseMoved:function (event) {
    return false;
},

in cocos2d-Html5 2.2.3, but it doesn’t work, tried with this code:

var nodeem = cc.Layer.extend({
  _mp: cc.MENU_HANDLER_PRIORITY,
  _ver: "default",

  ctor: function(ver) {
    this._super();
    this.init();
    if(ver) {
      this._mp -= 2;
      this._ver = ver;
    }
    this.setMousePriority(this._mp);
    this.setTouchPriority(this._mp);
    this.setTouchMode(cc.TOUCH_ONE_BY_ONE);
    this.setTouchEnabled(true);
    this.setMouseEnabled(true);
    console.log('init ' + this._ver);
  },

  onTouchBegan: function() {
    console.log('on touch began ' + this._ver);
    console.log('on touch began priority ' + this.getMousePriority());
    return true;
  },

  onMouseMoved: function() {
    console.log('on mouse moved ' + this._ver);
    console.log('on mouse moved priority ' + this.getMousePriority());
    return true;
  }
});

called in some layer:

this.addChild(new nodeem());
this.addChild(new nodeem('test'));

and get in console:

on mouse moved test TestScene.js:46
on mouse moved priority -130 TestScene.js:47
on mouse moved default TestScene.js:46
on mouse moved priority -128 TestScene.js:47
on touch began test TestScene.js:40
on touch began priority -130

I think it should work the same way as TouchDispatcher but it doesn’t. Anybody can help me ? Especially I’m focus to stop propagation using onMouseMoved

[UPDATE]
I cleared the example.
We can see that Touch is working correctly because the second ‘nodeem’ is swallowing touch so we’ve got only one with the lower priority (-130), but for Mouse it dosn’t work because we still have all mousemoved (-130 and -128 which should not be here).

Basically any layer that needs to have touch swallow needs to setTouchPriority with a lower TP value than the layers beneath it.

Read the discussion here:

May you should switch to 3.x:

// When "swallow touches" is true, then returning 'true' from the onTouchBegan method will "swallow" the touch event, preventing other listeners from using it.
        swallowTouches: true,

http://www.cocos2d-x.org/docs/manual/framework/html5/v3/eventManager/en

Thx, but I was not searching the resolution for Touch, because if you study my (not so clean) example you will find that priority for touch is working OK. The thing is not working is mousemoved. I cannot set mousepriority - it’s simply not working as in touch. I was wondering if it’s not completly implemented in cocos2d-html5 2.2.3 ?
Probably I will switch for 3.x but for now I’m involved in really big project and it’s not so simple to switch to 3.x so I need to handle mousemoved correctly for 2.2.3.

Yes, but see it as a little sandbox for testing :smile: Touch and mouse are both events, so I thought it was implemented in one dispatcher. But they have different dispatcher implementations.

I looked into the implementation and yes, you are right, the mouse dispatcher does not implement swallowing.
Look into the file:

cocos2d-html5-v2.2.3\cocos2d\touch_dispatcher\CCMouseDispatcher.js

and you can see, that the code for swallowing and targeted handler is missing. Only the standard handler is implemented.

You have to adapt it from:

cocos2d-html5-v2.2.3\cocos2d\touch_dispatcher\CCTouchDispatcher.js

@iQD is right about this, because we focused on touch events for mobiles and sorry that we don’t have a complete implementation for mouse dispatcher.
We will complete the mouse event implementation for 3.0, probably also for 2.x, but not very soon.
In the meantime, you can use TouchOneByOne, it will also respond to mouse events and it supports touch swallow.

@pandamicro thx for answer. Unfortunately I need swallow MouseMoved event :slight_smile: Waitin… for the implementation or meantime I will do it myself…