mirror of
https://github.com/szrpf/ActionShadowDemo.git
synced 2025-04-19 13:28:49 +00:00
22 lines
719 B
TypeScript
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;
|
||
|
});
|
||
|
}
|
||
|
}
|