关于实现全屏rigid拖拽 类似 mouseJoint 的解决方案

话不多说直接上代码

鼠标事件
private onEventEnd() {
is_chick = false;
}
//鼠标按下坐标
private up_posX: number = 0;
private up_posY: number = 0;
//小圈局部Y坐标 标记
private ring_y_mark: number = 0;
//鼠标按下
private onEventStart(event) {
this.up_posX = event.getLocationX();
this.up_posY = event.getLocationY();
targetX = this.ring.x
targetY = this.ring.y;
is_chick = true;
}

//鼠标移动
private onEventMove(event) {
    //设置目标点坐标
    // //--------x----------------
    targetX = targetX + (event.getLocationX() - this.up_posX);
    this.up_posX = event.getLocationX();
    // //--------y-----------------
    targetY = targetY + (event.getLocationY() - this.up_posY);
    this.up_posY = event.getLocationY();
}

//-----update------

//设置小球冲量
let vx = (targetX - this.ring.x) * 10;
let vy = (targetY - this.ring.y) * 10;
let vel = this.ring.getComponent(cc.RigidBody).linearVelocity;
if (Math.abs(targetX - this.ring.x) <= 10) {
this.ring.getComponent(cc.RigidBody).linearVelocity = cc.v2(0, vel.y);
}

    if (Math.abs(targetY - this.ring.y) <= 10) {
        this.ring.getComponent(cc.RigidBody).linearVelocity = cc.v2(vel.x, 0);
    }

    this.ring.getComponent(cc.RigidBody).linearVelocity = cc.v2(vx, vy);

//项目演示 微信小游戏

mark.

mark.