uiMain.ts 889 B

12345678910111213141516171819202122232425262728293031
  1. import { _decorator, Component, EventTouch, Input, Node } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('uiMain')
  4. export class uiMain extends Component {
  5. @property
  6. public planeSpeed = 1;
  7. @property(Node)
  8. public playerPlane: Node = null
  9. start() {
  10. // input.on(Input.EventType.TOUCH_START, this._touchStart, this);
  11. this.node.on(Input.EventType.TOUCH_MOVE, this._touchMove, this);
  12. }
  13. // update(deltaTime: number) {
  14. // }
  15. _touchMove(event: EventTouch) {
  16. const delta = event.getDelta();
  17. let pos = this.playerPlane.position;
  18. // x 上下, z 左右
  19. // this.node.setPosition(pos.x - 0.01 * this.speed * delta.x, pos.y, pos.z - 0.01 * this.speed * delta.y)
  20. this.playerPlane.setPosition(pos.x + 0.01 * this.planeSpeed * delta.y, pos.y, pos.z + 0.01 * this.planeSpeed * delta.x)
  21. }
  22. }