cocos creator 滑鼠跟隨朝向總結

2022-07-06 20:48:07 字數 1251 閱讀 9395

//此文是日常用到的一些獲取點選,跟隨,位移,朝向與兩點之間的距離總結

this.startpos = cc.v2(0, 0); //開始位置

this.endpos = cc.v2(0, 0); //結束位置

//獲取點選的位置

this.node.on(cc.node.eventtype.touch_start, function (event) , this);

//物體跟隨點選點

this.node.on(cc.node.eventtype.touch_move, function (event) ,this);

this.node.on(cc.node.eventtype.touch_end, function (event) , this);

//朝向1--跟隨滑鼠轉動

let direction = this.endpos.sub(this.startpos).normalize();

var radian = direction.signangle(cc.v2(1,0));

//將弧度轉換為尤拉角

var angle = radian / math.pi * 180;

this.bar.angle=-angle;

//朝向2--朝向目標點

var dx = this.magnetcard.x - target.x;

var dy = this.magnetcard.y - target.y;

var dir = cc.v2(dx, dy);

//根據朝向計算出夾角弧度

var angle = dir.signangle(cc.v2(1, 0));

//將弧度轉換為尤拉角

var degree = angle / math.pi * 180+90;

// target.rotation = degree;

//兩點之間距離

let worldpos = e.getlocation();

let localpos = this.node.converttonodespacear(worldpos);

this.endpos = cc.v2(localpos.x, localpos.y);

let distance = this.startpos.sub(this.endpos).mag();

console.log("--move:",this.endpos,distance)

this.bar.width=distance;

unity 獲取滑鼠跟鍵盤

unity3d滑鼠的獲取 自己可以試驗一下看看列印出來的值 獲取滑鼠螢幕的的滑動跟移動的函式 float aa input.getaxis mouse scrollwheel 1f 滑鼠滾輪 float bb input.getaxis mouse x 滑鼠的左右移動 float cc input....

studio 自定義view 圓形 跟滑鼠移動

構造方法,一般會重寫三個 用於初始化一些資料,或者其他東西 public class myviews extends view public myviews context context,nullable attributeset attrs public myviews context cont...

cocos creator 十二 問題

1 socket為什麼不能使用 2 cocos類之攝像機使用問題 1 在使用socket為什麼不能使用 if cc.sys.isnative opts this sio window.io connect this.ip opts this sio.on connect function data ...