記錄一下,好開心,感覺今天自己又學到東西了,對於屏幕雙擊事件本來還毫無頭緒的,今天得以解決總算沒白費加班,其實原理很簡單;
就是在點擊事件里做一個判斷,這個判斷就是需要獲取當前系統的時間的毫秒差,第一次點擊的時候直接return,
然后進行第二次點擊的時候也進行記錄,判斷兩者之間的時間差,進行函數響應,就可以解決了
1 timeUpdate : function() {
2 var t = new Date();
3 var hours = (t.getHours() > 9) ? t.getHours() : ("0" + t.getHours());//獲取系統小時(其實並沒有什么卵用)
4 var minutes = (t.getMinutes() > 9) ? t.getMinutes() : ("0" + t.getMinutes());//獲取系統分鍾(也並沒有什么卵用)
5 var seconds = (t.getMilliseconds() > 9) ? t.getMilliseconds() : ("0" + t.getMilliseconds());//這個是毫秒(需要用到哦)
6 var str = "" + hours + ":" + minutes+ ":" +seconds;//拼接起來就是時間了
7 this.tfClock.setString(str);
8 },
1 operateMyTile : function(sender, eventType) {//屏幕點擊事件函數處理
2
3 if(this.unlock) {
4
5 if (eventType == ccui.Widget.TOUCH_BEGAN) { //在此處判斷,點下觸碰生效 Touch_began
6 this.newSender = sender.clone();
7 sender.getParent().addChild(this.newSender, 100);
8 //var ddd=sender.getPosition();
9 this.newSender.setScale(1.3);
10 this.timeCount ++ ;
11
12 var t = new Date();
13 var hours = (t.getHours() > 9) ? t.getHours() : ("0" + t.getHours());//獲取當前系統小時
14 // var minutes = (t.getMinutes() > 9) ? t.getMinutes() : ("0" + t.getMinutes());
15 var seconds = t.getMilliseconds();//其實就這一句就可以了
16 //var str = "" + hours + ":" + minutes+ ":" + seconds;
17
18 this.sender = sender;
19
20 if(sender.seconds != null){
21 var ints = t.getMilliseconds() - sender.seconds;
22 if(1000 > ints){//核心判斷在這里(我是判斷在1秒內點擊兩次,1000毫秒等於1秒)
23 //這里的函數可以不用看,在這個判斷自定義函數即可
24 var id = this.upTiles.indexOf(sender);
25 var moveCard = this.cards[id];
26 gm.NetData.sendPlayMahjong(moveCard);
27 this.unSend = false;
28 this.canOut = false;
29 this.preemptiveOutTile(id, moveCard);
30 this.moveTileEndCB();
31 sender.seconds = null;
32 this.rankTile();
33 return;
34 }
35 }
36 sender.seconds = seconds;
37
38 this.myTileOldPos = sender.getPosition();
39
40 var testPos = this.sender.getTouchMovePosition();
41 if (testPos.y > 305) {
42 cc.log("..........testPos.y = " + testPos.y + " > 305..........");
43 }
44 }
45
46 else if(eventType == ccui.Widget.TOUCH_MOVED) {
47 if(this.sender != null) {
48 var pos = this.sender.getTouchMovePosition();
49 var spacePos = this.sender.getParent().convertToNodeSpace(pos);
50 this.sender.setPosition(spacePos);
51 this.newSender.setPosition(spacePos);
52
53 if (this.canOut) {
54 if (pos.y > 305) {
55 this.imgOutLine.setVisible(true);
56 } else {
57 this.imgOutLine.setVisible(false);
58 }
59 }
60 }
61 }
62
63 else {
64 if(this.sender != null) {
65 cc.log("..........Move Tile End..........");
66
67 var finalWorldPos = this.sender.getTouchMovePosition();
68 var finalPos = this.newSender.getPosition();
69 var id = this.upTiles.indexOf(this.sender);
70 var moveCard = this.cards[id];
71
72 var moveNum = id - parseInt((this.myTileOldPos.x - finalPos.x) / 67);
73 (moveNum < 0) ? (moveNum = 0) : moveNum;
74 (moveNum > this.cards.length) ? (moveNum = this.cards.length - 1) : moveNum;
75
76 cc.log("..........canOut = " + this.canOut + "..........");
77 if (this.canOut && (finalWorldPos.y > 305)) {
78 cc.log("..........finalWorldPos.y = " + finalWorldPos.y + " > 305..........");
79
80 gm.NetData.sendPlayMahjong(moveCard);
81 this.rankTile();
82 this.unSend = false;
83 this.canOut = false;
84 cc.log("..........Send Play..........");
85 cc.log("..........this.cards = " + this.cards + "..........");
86
87 this.preemptiveOutTile(id, moveCard);
88 } else {
89 if (moveCard != undefined) {
90 this.cards.splice(id, 1);
91 this.cards.splice(moveNum, 0, moveCard);
92 }
93 }
94
95 this.moveTileEndCB();
96 }
97 }
98 }
99 },