-
Creator 版本: 3.8.5
-
目标平台:Android
下面是代码
import { Vec3 } from ‘cc’;
import { EventTouch } from ‘cc’;
import { _decorator, Component, Node } from ‘cc’;
const { ccclass, property } = _decorator;
@ccclass(‘GmMoveTest’)
export class GmMoveTest extends Component {
protected start(): void {
this.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this);
this.node.on(Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
this.node.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
this.node.on(Node.EventType.TOUCH_CANCEL, this.onTouchEnd, this);
}
private onTouchStart(e: EventTouch) {
}
private _tmpV3 = new Vec3();
private onTouchMove(e: EventTouch) {
this.node.getPosition(this._tmpV3);
let delta = e.touch.getUIDelta();
this._tmpV3.x += delta.x;
this._tmpV3.y += delta.y;
this.node.setPosition(this._tmpV3);
}
private onTouchEnd(e: EventTouch) {
}
}
