uiMain.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { _decorator, Component, EventTouch, Input, Node } from 'cc';
  2. import { gameMangager } from '../framework/gameMangager';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('uiMain')
  5. export class uiMain extends Component {
  6. @property
  7. public planeSpeed = 1;
  8. @property(Node)
  9. public playerPlane: Node = null
  10. @property(gameMangager)
  11. public gamgeManager: gameMangager = null;
  12. start() {
  13. // input.on(Input.EventType.TOUCH_START, this._touchStart, this);
  14. this.node.on(Input.EventType.TOUCH_MOVE, this._touchMove, this);
  15. //
  16. this.node.on(Input.EventType.TOUCH_START, this._touchStart, this);
  17. this.node.on(Input.EventType.TOUCH_END, this._touchEnd, this);
  18. }
  19. // update(deltaTime: number) {
  20. // }
  21. _touchMove(event: EventTouch) {
  22. const delta = event.getDelta();
  23. let pos = this.playerPlane.position;
  24. // x 上下, z 左右
  25. // this.node.setPosition(pos.x - 0.01 * this.speed * delta.x, pos.y, pos.z - 0.01 * this.speed * delta.y)
  26. this.playerPlane.setPosition(pos.x + 0.01 * this.planeSpeed * delta.y, pos.y, pos.z + 0.01 * this.planeSpeed * delta.x)
  27. }
  28. _touchStart(event: EventTouch){
  29. console.log('开始发射');
  30. this.gamgeManager.isShooting(true)
  31. }
  32. _touchEnd(event: EventTouch){
  33. console.log('结束发射');
  34. this.gamgeManager.isShooting(false)
  35. }
  36. }