2023-05-14 17:15:55 +08:00

22 lines
719 B
TypeScript

const {ccclass, property} = cc._decorator;
@ccclass
export default class Helloworld extends cc.Component {
heroNode: cc.Node = null;
touchX: number = 0;
touchY: number = 0;
start () {
this.heroNode = this.node.getChildByName('Enemy');
this.heroNode.on(cc.Node.EventType.TOUCH_START, (event) => {
let pos = event.getLocation();
this.touchX = pos.x - this.heroNode.x;
this.touchY = pos.y - this.heroNode.y;
});
this.heroNode.on(cc.Node.EventType.TOUCH_MOVE, (event) => {
let pos = event.getLocation();
this.heroNode.x = pos.x - this.touchX;
this.heroNode.y = pos.y - this.touchY;
});
}
}