zoukankan      html  css  js  c++  java
  • cocos creator2.0 计算两点之间距离

     1 cc.Class({
     2     extends: cc.Component,
     3 
     4     properties: {
     5     },
     6 
     7     onLoad: function () {
     8         this.startPos = cc.v2(0, 0);  //开始位置
     9         this.endPos = cc.v2(0, 0);    //结束位置
    10 
    11         this.node.on(cc.Node.EventType.TOUCH_START, function (event) {
    12             this.startPos = cc.v2(event.getLocation().x, event.getLocation().y);
    13             //获取点击的位置
    14             cc.log("起始坐标点:x = " + event.getLocation().x + ", y = " + event.getLocation().y);
    15         }, this);
    16 
    17         this.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
    18             var delta = event.touch.getDelta();
    19             this.node.x += delta.x;
    20             this.node.y += delta.y;
    21         },this);
    22 
    23 
    24         this.node.on(cc.Node.EventType.TOUCH_END, function (event) {
    25 
    26             this.endPos = cc.v2(event.getLocation().x, event.getLocation().y);
    27             cc.log("终点坐标点 x :" + event.getLocation().x + ", 终点坐标点 y :" + event.getLocation().y );
    28 
    29             let distance = this.startPos.sub(this.endPos).mag();
    30             cc.log("移动距离 :" + distance);
    31         }, this);
    32 
    33     },
    34 
    35     update: function (dt) {
    36 
    37     },
    38 });
  • 相关阅读:
    vue子组件获取父组件方法
    css hack
    【Educational Codeforces Round 87 (Rated for Div. 2)】前4题
    【某次ks】20200512
    NoI Online 2反思
    RMQ&LCA
    杂谈
    高手训练矩乘T3
    0118ACM自闭赛
    网络流初步学习笔记
  • 原文地址:https://www.cnblogs.com/Hunter-541695/p/9888457.html
Copyright © 2011-2022 走看看