分享一个双击,或更多的点击的tapCout的方法

大家都知道之前的obj-c的版本是有tapCout这个东西的,可以通过它来判断是不是双击…

然后cocos2d-x3.0之后都没有实现这个方法…所以我下面自己实现了一次

testTouchEvent:function(){
        this.tapCount = 0;
        this.lastCount = 0;
        this.touchActTag = 1001;
            
        var listener = cc.EventListener.create({
            event: cc.EventListener.TOUCH_ONE_BY_ONE,
            onTouchBegan:function(touch, event){
                this.tapCount+=1;
                if(this.tapCount==1){
                    this.schedule(this.singleTap,0.25,1,0);
                }else{ 
                    if(this.tapCount==2) {
                        this.unschedule(this.singleTap);
 //如果你需要一双击就触发某个函数可以放这里
                    }
                    cc.log("double tap" + this.tapCount);

                    this.stopActionByTag(this.touchActTag);
                    var touchAction = cc.sequence(cc.delayTime(0.3),cc.callFunc(this.resetTouch,this));
                    touchAction.tag = this.touchActTag;
                    this.runAction(touchAction);
                }
                return true;
            }.bind(this),
        });
        cc.eventManager.addListener(listener,this);
    },
    singleTap:function(){
        this.unschedule(this.singleTap);
        this.tapCount = 0;
        cc.log("single tap");//单击
    },
    resetTouch:function(){
        cc.log("result" + this.tapCount);//多次点击
        this.tapCount = 0;
        this.lastCount = 0;
    },


```