cocosCreator關閉多點觸摸的問題

方法:改寫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);
        }
    };
},
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章