请问creator的按钮支持单点触摸吗?

这个是我最近才发现的问题,如果有两个按钮,手机上用手指同时点击这两个按钮则两个事件都会触发。有没有办法避免这个情况?

加个全局标志位吧

亲爱的小白鼠们,试试这样写能不能解决单点触摸问题:smile:

/***********************Node*************************/
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);
    }
};
/***********************Node*************************/

// 快速绑定点击函数 touchSilence-是否静默点击 Shield-是否有点击cdTime
cc.Node.prototype.quickBt = function(fn, touchSilence, Shield) {
this.unbindTouch();

this.lastClickTime = 0; // 上次点击时间
this.clickCdTime = 300  // 毫秒
this.canTouch = true;
this.hasTouchBegan = false;

this.on(cc.Node.EventType.TOUCH_START, function(event) {
    // console.log("TOUCH_START");
    if (this.canTouch == false)
        return;
    if (GM.hasTouchDown)
        return;

    this.hasTouchBegan = true;
    GM.hasTouchDown = true;
    this.BeganScale_ = this.getScale();
    this.BeganOpacity_ = this.opacity;
    if (!touchSilence) {
        this.setScale(this.BeganScale_*0.9);
        this.opacity = this.BeganOpacity_*0.9;
    };
}, this);

this.on(cc.Node.EventType.TOUCH_CANCEL, function(event) {
    if (this.canTouch == false)
        return;
    if (this.hasTouchBegan == false)
        return;

    GM.hasTouchDown = false;
    if (!touchSilence) {
        this.setScale(this.BeganScale_);
        this.opacity = this.BeganOpacity_;
    };
}, this);

this.on(cc.Node.EventType.TOUCH_END, function(event) {
    if (this.canTouch == false)
        return;
    if (this.hasTouchBegan == false)
        return;
    GM.hasTouchDown = false;
    if (!touchSilence) {
        this.setScale(this.BeganScale_);
        this.opacity = this.BeganOpacity_;

        var fullPath = "audio/common/Common_Panel_Dialog_Pop_Sound";
        if (GM.hasLoadSound[fullPath] == null) {
            cc.loader.loadRes(fullPath, cc.AudioClip, function (err, clip) {
                cc.audioEngine.playEffect(clip, false);
                GM.hasLoadSound[fullPath] = clip;
            });
        } else {
            cc.audioEngine.playEffect(GM.hasLoadSound[fullPath], false);
        }
    
    };
    if (!Shield) {
        var now = (new Date()).getTime();
        if (now - this.lastClickTime < this.clickCdTime) {
            console.log("---屏蔽过快点击---");
            return;
        };
        this.lastClickTime = now;
    };
    fn && fn(event);
    // console.log("TOUCH_END");
}, this);

this.autoClick = function () {
    fn();
}

return this;

};