2020-06-19 00:38:37 +08:00
|
|
|
class PlayerController extends Component {
|
|
|
|
|
private down: boolean = false;
|
|
|
|
|
private touchPoint: Vector2 = Vector2.zero;
|
2020-06-19 22:43:56 +08:00
|
|
|
private mover: Mover;
|
2020-06-19 00:38:37 +08:00
|
|
|
|
|
|
|
|
public onAddedToEntity(){
|
|
|
|
|
this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this);
|
|
|
|
|
this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchBegin, this);
|
|
|
|
|
this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private touchBegin(evt: egret.TouchEvent){
|
|
|
|
|
this.down = true;
|
|
|
|
|
this.touchPoint = new Vector2(evt.stageX, evt.stageY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private touchEnd(evt: egret.TouchEvent){
|
|
|
|
|
this.down = false;
|
|
|
|
|
this.touchPoint = new Vector2(evt.stageX, evt.stageY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public update(){
|
2020-06-19 22:43:56 +08:00
|
|
|
if (!this.mover)
|
|
|
|
|
this.mover = this.entity.getComponent<Mover>(Mover);
|
|
|
|
|
|
|
|
|
|
if (!this.mover)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-06-19 00:38:37 +08:00
|
|
|
if (this.down){
|
2020-06-21 10:27:15 +08:00
|
|
|
let camera = SceneManager.scene.camera;
|
2020-06-19 22:43:56 +08:00
|
|
|
this.mover.move(Input.touchPositionDelta);
|
|
|
|
|
console.log(Input.touchPositionDelta);
|
2020-06-19 00:38:37 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|