- 将技能配置中的动作类型从"atk"改为"max",以匹配英雄动画组件的逻辑 - 在动画组件中添加通用的`play`方法,并统一检查"max0"和"max1"动画的播放状态 - 防止多个动画同时播放导致的冲突问题
74 lines
2.4 KiB
TypeScript
74 lines
2.4 KiB
TypeScript
import { _decorator, Animation, AnimationState, CCClass, Component, } from "cc";
|
|
import { HeroViewComp } from "./HeroViewComp";
|
|
import { FacSet } from "../common/config/GameSet";
|
|
import { FlashSprite } from "./hit-flash-white/scripts/FlashSprite";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('HeroAnmComp')
|
|
export default class HeroAnmComp extends Component{
|
|
fsSprite:FlashSprite = null!;
|
|
private anmcon:any=null
|
|
private _hasStop = true;
|
|
private _atkIndex = 0;
|
|
private default_anim:string='Idle'
|
|
anms:any[]=["idle","move","stun","dead","buff","atk0","atk1","atk2","max0","max1"]
|
|
onLoad () {
|
|
this.anmcon=this.node.getComponent(Animation)
|
|
this.fsSprite = this.node.getComponent(FlashSprite);
|
|
this.anmcon.on(Animation.EventType.FINISHED, this.onAnimationFinished, this);
|
|
}
|
|
|
|
onDestroy() {
|
|
if (this.anmcon) {
|
|
this.anmcon.off(Animation.EventType.FINISHED, this.onAnimationFinished, this);
|
|
}
|
|
}
|
|
|
|
|
|
stop () {
|
|
this._hasStop = true;
|
|
}
|
|
onAnimationFinished(type:Animation.EventType, state:AnimationState){
|
|
if(state.name!="idle"&&state.name!="move"&&state.name!="dead"&&state.name!="stun"){
|
|
this.anmcon.play(this.default_anim)
|
|
}
|
|
}
|
|
atked(){
|
|
this.fsSprite.clickFlash();
|
|
}
|
|
move () {
|
|
if(this.anmcon.getState("move").isPlaying) return
|
|
this.anmcon.play("move")
|
|
this.default_anim='move'
|
|
}
|
|
atk () {
|
|
if(this.anmcon.getState("max0").isPlaying||this.anmcon.getState("max1").isPlaying) return
|
|
const atkName = `atk${this._atkIndex}`
|
|
this.anmcon.play(atkName)
|
|
this._atkIndex = (this._atkIndex + 1) % 3
|
|
}
|
|
max () {
|
|
if(this.anmcon.getState("max0").isPlaying||this.anmcon.getState("max1").isPlaying) return
|
|
this.anmcon.play("max0")
|
|
}
|
|
play(anm:string=""){
|
|
if(anm==="") return
|
|
if(this.anmcon.getState("max0").isPlaying||this.anmcon.getState("max1").isPlaying) return
|
|
this.anmcon.play(anm)
|
|
}
|
|
|
|
idle () {
|
|
if(this.anmcon.getState("idle").isPlaying) return
|
|
this.anmcon.play("idle")
|
|
this.default_anim='idle'
|
|
}
|
|
buff(){
|
|
if(this.anmcon.getState("max0").isPlaying||this.anmcon.getState("max1").isPlaying) return
|
|
this.anmcon.play("buff")
|
|
}
|
|
dead(){
|
|
if(this.anmcon.getState("dead").isPlaying) return
|
|
this.anmcon.play("dead")
|
|
}
|
|
}
|