cocos 版本 3.6.2
手指拖拽一个节点,节点跟着手指移动。
import { _decorator, Component, Node, Tween, Vec3, Vec2, Input, log, EventTouch, view } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('Test')
export class Test extends Component {
@property(Node)
myTouch: Node
touchStartPoint: Vec2 = new Vec2(0, 0)
start() {
this.myTouch.on(Input.EventType.TOUCH_CANCEL, () => {
log('TOUCH_CANCEL')
this.touchStartPoint = new Vec2(0, 0)
}, this)
this.myTouch.on(Input.EventType.TOUCH_END, () => {
log('TOUCH_END')
this.touchStartPoint = new Vec2(0, 0)
}, this)
this.myTouch.on(Input.EventType.TOUCH_MOVE, (event: EventTouch) => {
let node: Node = event.currentTarget
let pos = new Vec2()
let shit = pos.se