MapControll.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { _decorator, Component, Node, systemEvent, SystemEventType, Animation, Vec4, Vec2, Quat, Vec3, SkeletalAnimation, AnimationClip, AnimationState } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('MapControll')
  4. export class MapControll extends Component {
  5. @property({ type: AnimationClip })
  6. public moveClip: AnimationClip | null = null;
  7. @property
  8. private _touchVec2: Vec2 | null = null;
  9. @property
  10. private _startVec3: Vec3 | null = null;
  11. @property
  12. private _moveAnimation: AnimationState | null = null;
  13. @property
  14. private _startTouch = false
  15. @property
  16. private _timer;
  17. start() {
  18. systemEvent.on(SystemEventType.TOUCH_START, this.onTouchStart, this)
  19. systemEvent.on(SystemEventType.TOUCH_MOVE, this.onTouchMove, this)
  20. systemEvent.on(SystemEventType.TOUCH_END, this.onTouchEnd, this)
  21. }
  22. onTouchEnd() {
  23. this._startTouch = false;
  24. if (this._moveAnimation) {
  25. this.startMove();
  26. }
  27. }
  28. onTouchStart(e) {
  29. this._startTouch = true;
  30. if (this._moveAnimation) {
  31. this._moveAnimation.pause();
  32. }
  33. this._touchVec2 = new Vec2(e._point);
  34. let vec3 = new Vec3();
  35. this.node.rotation.getEulerAngles(vec3);
  36. this._startVec3 = vec3;
  37. }
  38. onTouchMove(e) {
  39. let _point = new Vec2();
  40. Vec2.subtract(_point, e._point, this._touchVec2);
  41. this.node.setRotationFromEuler(this._startVec3.x - _point.y, this._startVec3.y + _point.x, 0);
  42. }
  43. onDestroy() {
  44. systemEvent.off(SystemEventType.TOUCH_START, this.onTouchStart, this)
  45. systemEvent.off(SystemEventType.TOUCH_MOVE, this.onTouchMove, this)
  46. systemEvent.off(SystemEventType.TOUCH_END, this.onTouchEnd, this)
  47. this._moveAnimation.destroy();
  48. }
  49. startMove() { }
  50. }