zoukankan      html  css  js  c++  java
  • cocos2d-x JS 获取当前系统时间(解决屏幕双击点击事件)

    记录一下,好开心,感觉今天自己又学到东西了,对于屏幕双击事件本来还毫无头绪的,今天得以解决总算没白费加班,其实原理很简单;
    就是在点击事件里做一个判断,这个判断就是需要获取当前系统的时间的毫秒差,第一次点击的时候直接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 },
     
  • 相关阅读:
    Vue 中动态添加class(使用v-bind:class)
    Vue 过滤器的使用
    Huxley 是一个用于Web应用 UI 测试的工具
    showmessage函数里
    [Php] PHPExcel读取Excel文件(或来自客户端上传的)并返回二维数组
    async-validator -- git地址
    Antd Upload组件上传文件至php后端, php拿到对应的文件名(二: vue实现)
    Antd Upload组件上传文件至php后端, php拿到对应的文件名
    对数据库中一个timestamp类型字段时间上作加减
    小学生作文怎么辅导?
  • 原文地址:https://www.cnblogs.com/luorende/p/6628668.html
Copyright © 2011-2022 走看看