记录一下,好开心,感觉今天自己又学到东西了,对于屏幕双击事件本来还毫无头绪的,今天得以解决总算没白费加班,其实原理很简单;
就是在点击事件里做一个判断,这个判断就是需要获取当前系统的时间的毫秒差,第一次点击的时候直接return,
然后进行第二次点击的时候也进行记录,判断两者之间的时间差,进行函数响应,就可以解决了
timeUpdate : function() {
var t = new Date();
var hours = (t.getHours() > 9) ? t.getHours() : ("0" + t.getHours());//获取系统小时(其实并没有什么卵用)
var minutes = (t.getMinutes() > 9) ? t.getMinutes() : ("0" + t.getMinutes());//获取系统分钟(也并没有什么卵用)
var seconds = (t.getMilliseconds() > 9) ? t.getMilliseconds() : ("0" + t.getMilliseconds());//这个是毫秒(需要用到哦)
var str = "" + hours + ":" + minutes+ ":" +seconds;//拼接起来就是时间了
this.tfClock.setString(str);
},
operateMyTile : function(sender, eventType) {//屏幕点击事件函数处理
if(this.unlock) {
if (eventType == ccui.Widget.TOUCH_BEGAN) { //在此处判断,点下触碰生效 Touch_began
this.newSender = sender.clone();
sender.getParent().addChild(this.newSender, 100);
//var ddd=sender.getPosition();
this.newSender.setScale(1.3);
this.timeCount ++ ;
var t = new Date();
var hours = (t.getHours() > 9) ? t.getHours() : ("0" + t.getHours());//获取当前系统小时
// var minutes = (t.getMinutes() > 9) ? t.getMinutes() : ("0" + t.getMinutes());
var seconds = t.getMilliseconds();//其实就这一句就可以了
//var str = "" + hours + ":" + minutes+ ":" + seconds;
this.sender = sender;
if(sender.seconds != null){
var ints = t.getMilliseconds() - sender.seconds;
if(1000 > ints){//核心判断在这里(我是判断在1秒内点击两次,1000毫秒等于1秒)
//这里的函数可以不用看,在这个判断自定义函数即可
var id = this.upTiles.indexOf(sender);
var moveCard = this.cards[id];
gm.NetData.sendPlayMahjong(moveCard);
this.unSend = false;
this.canOut = false;
this.preemptiveOutTile(id, moveCard);
this.moveTileEndCB();
sender.seconds = null;
this.rankTile();
return;
}
}
sender.seconds = seconds;
this.myTileOldPos = sender.getPosition();
var testPos = this.sender.getTouchMovePosition();
if (testPos.y > 305) {
cc.log("..........testPos.y = " + testPos.y + " > 305..........");
}
}
else if(eventType == ccui.Widget.TOUCH_MOVED) {
if(this.sender != null) {
var pos = this.sender.getTouchMovePosition();
var spacePos = this.sender.getParent().convertToNodeSpace(pos);
this.sender.setPosition(spacePos);
this.newSender.setPosition(spacePos);
if (this.canOut) {
if (pos.y > 305) {
this.imgOutLine.setVisible(true);
} else {
this.imgOutLine.setVisible(false);
}
}
}
}
else {
if(this.sender != null) {
cc.log("..........Move Tile End..........");
var finalWorldPos = this.sender.getTouchMovePosition();
var finalPos = this.newSender.getPosition();
var id = this.upTiles.indexOf(this.sender);
var moveCard = this.cards[id];
var moveNum = id - parseInt((this.myTileOldPos.x - finalPos.x) / 67);
(moveNum < 0) ? (moveNum = 0) : moveNum;
(moveNum > this.cards.length) ? (moveNum = this.cards.length - 1) : moveNum;
cc.log("..........canOut = " + this.canOut + "..........");
if (this.canOut && (finalWorldPos.y > 305)) {
cc.log("..........finalWorldPos.y = " + finalWorldPos.y + " > 305..........");
gm.NetData.sendPlayMahjong(moveCard);
this.rankTile();
this.unSend = false;
this.canOut = false;
cc.log("..........Send Play..........");
cc.log("..........this.cards = " + this.cards + "..........");
this.preemptiveOutTile(id, moveCard);
} else {
if (moveCard != undefined) {
this.cards.splice(id, 1);
this.cards.splice(moveNum, 0, moveCard);
}
}
this.moveTileEndCB();
}
}
}
},