去掉原先spine 英雄怪物
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { _decorator, CCClass, Component, sp } from "cc";
|
||||
import { _decorator, Animation, AnimationState, CCClass, Component, } from "cc";
|
||||
import { HeroViewComp } from "./HeroViewComp";
|
||||
import { FacSet } from "../common/config/BoxSet";
|
||||
const { ccclass, property } = _decorator;
|
||||
@@ -6,114 +6,47 @@ const { ccclass, property } = _decorator;
|
||||
@ccclass('HeroAnmComp')
|
||||
export default class HeroAnmComp extends Component{
|
||||
|
||||
mixTime:number= 0.2;
|
||||
|
||||
private spine?: sp.Skeleton;
|
||||
private anmcon:any=null
|
||||
private _hasStop = true;
|
||||
private default_anim:string='Idle'
|
||||
anms:any[]=["idle","move","atk","max","debbuff","atked"]
|
||||
onLoad () {
|
||||
var spine = this.spine = this.getComponent('sp.Skeleton') as sp.Skeleton;
|
||||
this._setMix('Walking', 'Idle');
|
||||
this._setMix('Walking', 'Attacking');
|
||||
this._setMix('Walking', 'Taunt');
|
||||
this._setMix('Walking', 'Hurt');
|
||||
this._setMix('Idle', 'Attacking');
|
||||
this._setMix('Idle', 'Taunt');
|
||||
this._setMix('Idle', 'Walking');
|
||||
this._setMix('Idle', 'Hurt');
|
||||
this._setMix('Attacking', 'Idle');
|
||||
this._setMix('Attacking', 'Walking');
|
||||
this._setMix('Attacking', 'Hurt');
|
||||
this._setMix('Attacking', 'Taunt');
|
||||
this._setMix('Taunt', 'Walking');
|
||||
this._setMix('Taunt', 'Idle');
|
||||
this._setMix('Taunt', 'Attacking');
|
||||
this._setMix('Taunt', 'Hurt');
|
||||
this._setMix('Hurt', 'Idle');
|
||||
this._setMix('Hurt', 'Attacking');
|
||||
this._setMix('Hurt', 'Taunt');
|
||||
this._setMix('Hurt', 'Walking');
|
||||
|
||||
spine.setCompleteListener((trackEntry) => {
|
||||
var animationName = trackEntry.animation ? trackEntry.animation.name : "";
|
||||
if (animationName === 'Attacking'||animationName==='Taunt'||animationName==='Hurt') {
|
||||
this.spine!.clearTrack(1);
|
||||
this.spine?.setAnimation(0, this.default_anim, true);
|
||||
}
|
||||
var loopCount = Math.floor(trackEntry.trackTime / trackEntry.animationEnd);
|
||||
// console.log("[track %s][animation %s] complete: %s", trackEntry.trackIndex, animationName, loopCount);
|
||||
});
|
||||
spine.setEventListener(((trackEntry:any, event:any) => {
|
||||
var animationName = trackEntry.animation ? trackEntry.animation.name : "";
|
||||
// console.log("[track %s][animation %s] event: %s, %s, %s, %s", trackEntry.trackIndex, animationName, event.data.name, event.intValue, event.floatValue, event.stringValue);
|
||||
}) as any);
|
||||
|
||||
this._hasStop = false;
|
||||
this.anmcon=this.node.getComponent(Animation)
|
||||
this.anmcon.on(Animation.EventType.FINISHED, this.onAnimationFinished, this);
|
||||
}
|
||||
|
||||
// OPTIONS
|
||||
|
||||
toggleDebugSlots () {
|
||||
this.spine!.debugSlots = !this.spine?.debugSlots;
|
||||
}
|
||||
|
||||
toggleDebugBones () {
|
||||
this.spine!.debugBones = !this.spine?.debugBones;
|
||||
}
|
||||
|
||||
toggleDebugMesh () {
|
||||
this.spine!.debugMesh = !this.spine?.debugMesh;
|
||||
}
|
||||
|
||||
toggleUseTint () {
|
||||
this.spine!.useTint = !this.spine?.useTint;
|
||||
}
|
||||
|
||||
toggleTimeScale () {
|
||||
if (this.spine!.timeScale === 1.0) {
|
||||
this.spine!.timeScale = 0.3;
|
||||
}
|
||||
else {
|
||||
this.spine!.timeScale = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
// ANIMATIONS
|
||||
|
||||
stop () {
|
||||
// this.spine?.clearTrack(0);
|
||||
this._hasStop = true;
|
||||
}
|
||||
|
||||
move () {
|
||||
if (this._hasStop) {
|
||||
this.spine?.setToSetupPose();
|
||||
onAnimationFinished(type:Animation.EventType, state:AnimationState){
|
||||
console.log("[HeroAnmComp]: 动画播放完毕",state.name)
|
||||
if(state.name!="idle"&&state.name!="move"){
|
||||
this.anmcon.play(this.default_anim)
|
||||
}
|
||||
// console.log("do move",this.spine?.animation);
|
||||
this.spine?.setAnimation(0, 'Walking', true);
|
||||
this.default_anim='Walking'
|
||||
this._hasStop = false;
|
||||
}
|
||||
move () {
|
||||
if(this.anmcon.getState("move").isPlaying) return
|
||||
this.anmcon.play("move")
|
||||
this.default_anim='move'
|
||||
}
|
||||
atk () {
|
||||
this.spine?.setAnimation(1, 'Attacking', false);
|
||||
if(this.anmcon.getState("atk").isPlaying) return
|
||||
this.anmcon.play("atk")
|
||||
}
|
||||
max () {
|
||||
this.spine?.setAnimation(1, 'Taunt', false);
|
||||
if(this.anmcon.getState("max").isPlaying) return
|
||||
this.anmcon.play("max")
|
||||
}
|
||||
atked () {
|
||||
if(this.spine.animation==='Hurt') return
|
||||
this.spine?.setAnimation(1, 'Hurt', false);
|
||||
if(this.anmcon.getState("atked").isPlaying) return
|
||||
this.anmcon.play("atked")
|
||||
}
|
||||
idle () {
|
||||
this.spine?.setToSetupPose();
|
||||
if(this.spine?.animation==='Idle') return
|
||||
// console.log("do idle",this.spine.animation);
|
||||
this.spine?.setAnimation(0, 'Idle', true);
|
||||
this.default_anim='Idle'
|
||||
if(this.anmcon.getState("idle").isPlaying) return
|
||||
this.anmcon.play("idle")
|
||||
this.default_anim='idle'
|
||||
}
|
||||
|
||||
_setMix (anim1: string, anim2: string) {
|
||||
this.spine?.setMix(anim1, anim2, this.mixTime);
|
||||
this.spine?.setMix(anim2, anim1, this.mixTime);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user