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 });
  • 相关阅读:
    进制
    enum
    文件操作fstream
    文件读取 FILE
    static_cast、dynamic_cast、reinterpret_cast、和const_c
    std::max 错误
    boost 时间
    c++ new 和delete
    c++ static静态
    BOOST 之filesystem, path
  • 原文地址:https://www.cnblogs.com/Hunter-541695/p/9888457.html
Copyright © 2011-2022 走看看