123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- import { _decorator, Component, Label, Node, tween, UITransform, Vec3, view } from 'cc';
- import { UserManager } from '../Manager/UserMgr';
- import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDispatcher';
- import { GameEvent } from '../Enum/GameEvent';
- import { AliensAudioMgr } from '../Manager/AliensAudioMgr';
- import { GlobalConfig } from 'db://assets/start/Config/GlobalConfig';
- const { ccclass, property } = _decorator;
- //嘲讽文本
- const tauntTxt = [
- 'Your level is also too poor',
- 'You loser',
- 'It would have been over long ago if someone else came'
- ]
- @ccclass('TauntComponent')
- export class TauntComponent extends Component {
- @property(Label)
- tauntLabel: Label = null!;
- private _originPos:Vec3 = null!;
- private _isAnimating: boolean = false;
- //嘲讽时间间隔
- tauntIntervalTime: number = 0;
- start() {
- const tauntTime = UserManager.instance.userModel.tauntIntervalTime
- this.tauntIntervalTime = tauntTime;
- if(GlobalConfig.isDebug){
- this.tauntIntervalTime = 10;
- }
- this._originPos = this.node.position.clone();
- EventDispatcher.instance.on(GameEvent.EVENT_GAME_COUNTDOWN_START,this.startTauntSchedule,this)
- }
- private startTauntSchedule() {
- this.schedule(this.playTauntAnimation, this.tauntIntervalTime);
- }
- //嘲讽动画
- taunt() {
- AliensAudioMgr.playOneShot(AliensAudioMgr.getMusicIdName(6), 1.0);
- if(this._isAnimating) return;
- this._isAnimating = true;
-
- // 设置随机嘲讽文本
- this.tauntLabel.string = this.getRandomTauntTxt();
-
- // 计算屏幕左侧位置
- const screenLeft = -view.getVisibleSize().width / 2;
- const width = this.node.getComponent(UITransform).width;
- const targetPos = new Vec3(screenLeft + width / 2, this._originPos.y, this._originPos.z);
-
- // 动画到屏幕左侧(1秒)
- tween(this.node.position)
- .to(1, targetPos, {
- easing: 'quadOut',
- onUpdate: (target: Vec3) => {
- this.node.position = target;
- }
- })
- .call(() => {
- // 停留1秒后再执行返回动画
- this.scheduleOnce(() => {
- tween(this.node.position)
- .to(2, this._originPos, {
- easing: 'quadIn',
- onUpdate: (target: Vec3) => {
- this.node.position = target;
- },
- onComplete: () => {
- this._isAnimating = false;
- }
- })
- .start();
- }, 1);
- })
- .start();
- }
- // 定时播放嘲讽动画
- private playTauntAnimation() {
- this.taunt();
- }
- //随机获取嘲讽文本
- getRandomTauntTxt() {
- const index = Math.floor(Math.random() * tauntTxt.length);
- return tauntTxt[index];
- }
- protected onDestroy(): void {
- this.unschedule(this.playTauntAnimation);
- EventDispatcher.instance.off(GameEvent.EVENT_GAME_COUNTDOWN_START,this.startTauntSchedule,this)
- }
- }
|