Files
heros/assets/script/game/hero/HeroAnmComp.ts
2025-10-23 10:43:15 +08:00

50 lines
1.5 KiB
TypeScript

import { _decorator, Animation, AnimationState, CCClass, Component, } from "cc";
import { HeroViewComp } from "./HeroViewComp";
import { FacSet } from "../common/config/BoxSet";
const { ccclass, property } = _decorator;
@ccclass('HeroAnmComp')
export default class HeroAnmComp extends Component{
private anmcon:any=null
private _hasStop = true;
private default_anim:string='Idle'
anms:any[]=["idle","move","atk1","atk2","atk","max","max1","stun","dead","buff"]
onLoad () {
this.anmcon=this.node.getComponent(Animation)
this.anmcon.on(Animation.EventType.FINISHED, this.onAnimationFinished, this);
}
stop () {
this._hasStop = true;
}
onAnimationFinished(type:Animation.EventType, state:AnimationState){
// console.log("[HeroAnmComp]: 动画播放完毕",state.name)
if(state.name!="idle"&&state.name!="move"){
this.anmcon.play(this.default_anim)
}
}
move () {
if(this.anmcon.getState("move").isPlaying) return
this.anmcon.play("move")
this.default_anim='move'
}
atk () {
if(this.anmcon.getState("atk").isPlaying) return
this.anmcon.play("atk")
}
max () {
if(this.anmcon.getState("max").isPlaying) return
this.anmcon.play("max")
}
idle () {
if(this.anmcon.getState("idle").isPlaying) return
this.anmcon.play("idle")
this.default_anim='idle'
}
buff(){
if(this.anmcon.getState("buff").isPlaying) return
this.anmcon.play("buff")
}
}