|
@@ -1,4 +1,4 @@
|
|
-import { _decorator, Component, ERaycast2DType, find, Label, Node, NodeEventType, PhysicsSystem2D, Tween, tween, v2, v3, Vec2, Vec3 } from 'cc';
|
|
|
|
|
|
+import { _decorator, Component, ERaycast2DType, EventTouch, find, Label, Node, NodeEventType, PhysicsSystem2D, Tween, tween, v2, v3, Vec2, Vec3 } from 'cc';
|
|
import { GameEvent } from './Script/Enum/GameEvent';
|
|
import { GameEvent } from './Script/Enum/GameEvent';
|
|
import { LevelManager } from './Script/Manager/LevelMgr';
|
|
import { LevelManager } from './Script/Manager/LevelMgr';
|
|
import { GameUtil } from './Script/GameUtil';
|
|
import { GameUtil } from './Script/GameUtil';
|
|
@@ -18,6 +18,9 @@ const duration = 0.3;
|
|
@ccclass('RoosterAliens')
|
|
@ccclass('RoosterAliens')
|
|
export class RoosterAliens extends Component {
|
|
export class RoosterAliens extends Component {
|
|
|
|
|
|
|
|
+ private _touchStartTime: number = 0;
|
|
|
|
+ private _isTouchMoving: boolean = false;
|
|
|
|
+
|
|
onLoad() {
|
|
onLoad() {
|
|
AliensAudioMgr.initilize();
|
|
AliensAudioMgr.initilize();
|
|
AliensAudioMgr.play(AliensAudioMgr.getMusicIdName(1), 1.0);
|
|
AliensAudioMgr.play(AliensAudioMgr.getMusicIdName(1), 1.0);
|
|
@@ -25,7 +28,7 @@ export class RoosterAliens extends Component {
|
|
LevelManager.instance.initilizeModel();
|
|
LevelManager.instance.initilizeModel();
|
|
AliensGlobalInstance.instance.initUI(); //初始化u
|
|
AliensGlobalInstance.instance.initUI(); //初始化u
|
|
this.registerListener();
|
|
this.registerListener();
|
|
- this.resetMgr();
|
|
|
|
|
|
+ this.resetMgr();
|
|
}
|
|
}
|
|
|
|
|
|
private resetMgr() {
|
|
private resetMgr() {
|
|
@@ -53,13 +56,16 @@ export class RoosterAliens extends Component {
|
|
|
|
|
|
btnSet.on(NodeEventType.TOUCH_END, () => this.onClickSet(), this);
|
|
btnSet.on(NodeEventType.TOUCH_END, () => this.onClickSet(), this);
|
|
btnPoint.on(NodeEventType.TOUCH_END, () => this.onClickAim(), this);
|
|
btnPoint.on(NodeEventType.TOUCH_END, () => this.onClickAim(), this);
|
|
- btnPointFrame.on(NodeEventType.TOUCH_END, () => this.onClickResetAim(), this);
|
|
|
|
|
|
+ // btnPointFrame.on(NodeEventType.TOUCH_END, () => this.onClickResetAim(), this);
|
|
|
|
+ btnPointFrame.on(NodeEventType.TOUCH_START, this.frameTouchStart, this);
|
|
|
|
+ btnPointFrame.on(NodeEventType.TOUCH_MOVE, this.frameTouchMove, this);
|
|
|
|
+ btnPointFrame.on(NodeEventType.TOUCH_END, this.frameTouchEnd, this);
|
|
btnShoot.on(NodeEventType.TOUCH_END, () => this.onShoot(), this);
|
|
btnShoot.on(NodeEventType.TOUCH_END, () => this.onShoot(), this);
|
|
btnStart.on(NodeEventType.TOUCH_END, () => this.onStart(), this);
|
|
btnStart.on(NodeEventType.TOUCH_END, () => this.onStart(), this);
|
|
|
|
|
|
- EventDispatcher.instance.on(GameEvent.EVENT_GAME_ENTER,this.onStart,this);
|
|
|
|
- EventDispatcher.instance.on(GameEvent.EVENT_CAMERA_HIDE_AIM,this.onClickResetAim,this);
|
|
|
|
- EventDispatcher.instance.on(GameEvent.EVENT_GAME_BACK_HOME,this.backHome,this);
|
|
|
|
|
|
+ EventDispatcher.instance.on(GameEvent.EVENT_GAME_ENTER, this.onStart, this);
|
|
|
|
+ EventDispatcher.instance.on(GameEvent.EVENT_CAMERA_HIDE_AIM, this.onClickResetAim, this);
|
|
|
|
+ EventDispatcher.instance.on(GameEvent.EVENT_GAME_BACK_HOME, this.backHome, this);
|
|
}
|
|
}
|
|
|
|
|
|
private onClickSet(): void {
|
|
private onClickSet(): void {
|
|
@@ -87,6 +93,29 @@ export class RoosterAliens extends Component {
|
|
EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_RESET_AIM);
|
|
EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_RESET_AIM);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private frameTouchStart(event: EventTouch): void {
|
|
|
|
+ this._touchStartTime = Date.now();
|
|
|
|
+ this._isTouchMoving = false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private frameTouchMove(event: EventTouch): void {
|
|
|
|
+ // 检查触摸时长是否超过0.3秒
|
|
|
|
+ if (Date.now() - this._touchStartTime >= 300) {
|
|
|
|
+ this._isTouchMoving = true;
|
|
|
|
+ EventDispatcher.instance.emit(GameEvent.EVENT_FRAME_TOUCH_MOVE, event);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private frameTouchEnd(event: EventTouch): void {
|
|
|
|
+ if (!this._isTouchMoving) {
|
|
|
|
+ this.onClickResetAim();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 重置状态
|
|
|
|
+ this._touchStartTime = 0;
|
|
|
|
+ this._isTouchMoving = false;
|
|
|
|
+ }
|
|
|
|
+
|
|
private onShoot(): void {
|
|
private onShoot(): void {
|
|
AliensAudioMgr.playOneShot(AliensAudioMgr.getMusicIdName(4), 1.0);
|
|
AliensAudioMgr.playOneShot(AliensAudioMgr.getMusicIdName(4), 1.0);
|
|
EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_SHOOT);
|
|
EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_SHOOT);
|
|
@@ -110,7 +139,7 @@ export class RoosterAliens extends Component {
|
|
|
|
|
|
private backHome(): void {
|
|
private backHome(): void {
|
|
AliensGlobalInstance.instance.homeUI.active = true;
|
|
AliensGlobalInstance.instance.homeUI.active = true;
|
|
- AliensGlobalInstance.instance.battleUI.active = false;
|
|
|
|
|
|
+ AliensGlobalInstance.instance.battleUI.active = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|