方法:改写node的派发事件,当有多个相应的时候不去进行dispatch
在游戏开启的时候把node原来的方法:
cc.Node.prototype.dispatchEvent ƒ (event) {
_doDispatchEvent(this, event);
cachedArray.length = 0;
}、
改为;
在游戏必经的文件中调用一次;改写node的dispatchEvent的方法
DealMulityEventListener:function(){ cc.Node.maxTouchNum = 1; cc.Node.touchNum = 0; var __dispatchEvent__ = cc.Node.prototype.dispatchEvent; cc.Node.prototype.dispatchEvent = function (event) { switch (event.type) { case 'touchstart': if (cc.Node.touchNum < cc.Node.maxTouchNum) { cc.Node.touchNum++; this._canTouch = true; __dispatchEvent__.call(this, event); } break; case 'touchmove': if (!this._canTouch && cc.Node.touchNum < cc.Node.maxTouchNum) { this._canTouch = true; cc.Node.touchNum++; } if (this._canTouch) { __dispatchEvent__.call(this, event); } break; case 'touchend': if (this._canTouch) { this._canTouch = false; cc.Node.touchNum--; __dispatchEvent__.call(this, event); } break; case 'touchcancel': if (this._canTouch) { this._canTouch = false; cc.Node.touchNum--; __dispatchEvent__.call(this, event); } break; default: __dispatchEvent__.call(this, event); } }; },