动画替换完成
This commit is contained in:
@@ -1,84 +1,63 @@
|
||||
/*
|
||||
* @Author: dgflash
|
||||
* @Date: 2022-08-04 15:08:35
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-08-04 15:26:26
|
||||
*/
|
||||
import { Color, Component, EventTouch, sp, Vec3, _decorator ,Animation, AnimationClip, AnimationState,} from "cc";
|
||||
import { Color, Component, EventTouch, sp, Vec3, _decorator ,} from "cc";
|
||||
import HeroAnmComp from "./HeroAnmComp";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**
|
||||
* RPG SPINE角色模型
|
||||
*/
|
||||
@ccclass('HeroSpine')
|
||||
export class HeroSpine extends Component {
|
||||
@property(Animation)
|
||||
animator: Animation = null!;
|
||||
|
||||
@property(HeroAnmComp)
|
||||
anm: HeroAnmComp = null;
|
||||
|
||||
status:string="Idle";
|
||||
|
||||
onLoad() {
|
||||
// 角色控制组件
|
||||
this.initAnimator();
|
||||
this.idle_clip = this.animator.clips[0];
|
||||
this.atk_clip = this.animator.clips[1];
|
||||
this.move_clip = this.animator.clips[2];
|
||||
this.default_clip=this.move_clip.name;
|
||||
let animation = this.animator.getComponent(Animation);
|
||||
animation.on(Animation.EventType.FINISHED, this.onAnimationEvent, this)
|
||||
|
||||
}
|
||||
protected start(): void {
|
||||
this.move();
|
||||
}
|
||||
/** 初始化动画 */
|
||||
protected initAnimator() {
|
||||
this.animator=this.node.getChildByName("anm").getComponent(Animation);
|
||||
|
||||
// console.log("mon spine init",this.animator);
|
||||
|
||||
}
|
||||
in_playing(){
|
||||
if(this.animator.getState(this.atk_clip.name).isPlaying) return true;
|
||||
if(this.animator.getState(this.idle_clip.name).isPlaying) return true;
|
||||
if(this.animator.getState(this.move_clip.name).isPlaying) return true;
|
||||
return false;
|
||||
|
||||
}
|
||||
onAnimationEvent(type: Animation.EventType, state: AnimationState){
|
||||
if(type==Animation.EventType.FINISHED){
|
||||
// console.log("animator end",state.name);
|
||||
if(state.name==this.atk_clip.name){
|
||||
this.default();
|
||||
}
|
||||
}
|
||||
change_status(value:string){
|
||||
this.status=value
|
||||
}
|
||||
change_default(value:string){
|
||||
// console.log("change default",value);
|
||||
this.default_clip=value;
|
||||
|
||||
}
|
||||
default() {
|
||||
if(!this.in_playing()){
|
||||
// console.log("do default");
|
||||
this.animator.play(this.default_clip);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
idle(){
|
||||
if(!this.in_playing()){
|
||||
console.log("do idle");
|
||||
this.animator.play(this.idle_clip.name);
|
||||
}
|
||||
// console.log("do Idle");
|
||||
if(this.status=="Idle") return
|
||||
this.status="Idle"
|
||||
this.anm.idle()
|
||||
}
|
||||
atk() {
|
||||
// console.log("do atk");
|
||||
this.animator.play(this.atk_clip.name);
|
||||
this.anm.atk()
|
||||
}
|
||||
max(){
|
||||
// console.log("do max");
|
||||
this.anm.max()
|
||||
}
|
||||
|
||||
|
||||
|
||||
move(){
|
||||
if(!this.animator.getState(this.move_clip.name).isPlaying) {
|
||||
console.log("doing move");
|
||||
this.animator.play(this.move_clip.name);
|
||||
}
|
||||
// console.log("doing move");
|
||||
if(this.status=="move") return
|
||||
this.status="move"
|
||||
this.anm.move()
|
||||
}
|
||||
atked() {
|
||||
// console.log("do atked");
|
||||
this.anm.atked()
|
||||
}
|
||||
onDestroy() {
|
||||
this.node.destroy();
|
||||
|
||||
Reference in New Issue
Block a user