| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- import { _decorator, Component, Node, systemEvent, SystemEventType, Animation, Vec4, Vec2, Quat, Vec3, SkeletalAnimation, AnimationClip, AnimationState } from 'cc';
- const { ccclass, property } = _decorator;
- @ccclass('MapControll')
- export class MapControll extends Component {
- @property({ type: AnimationClip })
- public moveClip: AnimationClip | null = null;
- @property
- private _touchVec2: Vec2 | null = null;
- @property
- private _startVec3: Vec3 | null = null;
- @property
- private _moveAnimation: AnimationState | null = null;
- @property
- private _startTouch = false
- @property
- private _timer;
- start() {
- systemEvent.on(SystemEventType.TOUCH_START, this.onTouchStart, this)
- systemEvent.on(SystemEventType.TOUCH_MOVE, this.onTouchMove, this)
- systemEvent.on(SystemEventType.TOUCH_END, this.onTouchEnd, this)
- }
- onTouchEnd() {
- this._startTouch = false;
- if (this._moveAnimation) {
- this.startMove();
- }
- }
- onTouchStart(e) {
- this._startTouch = true;
- if (this._moveAnimation) {
- this._moveAnimation.pause();
- }
- this._touchVec2 = new Vec2(e._point);
- let vec3 = new Vec3();
- this.node.rotation.getEulerAngles(vec3);
- this._startVec3 = vec3;
- }
- onTouchMove(e) {
- let _point = new Vec2();
- Vec2.subtract(_point, e._point, this._touchVec2);
- this.node.setRotationFromEuler(this._startVec3.x - _point.y, this._startVec3.y + _point.x, 0);
- }
- onDestroy() {
- systemEvent.off(SystemEventType.TOUCH_START, this.onTouchStart, this)
- systemEvent.off(SystemEventType.TOUCH_MOVE, this.onTouchMove, this)
- systemEvent.off(SystemEventType.TOUCH_END, this.onTouchEnd, this)
- this._moveAnimation.destroy();
- }
- startMove() { }
- }
|