99 lines
3.0 KiB
TypeScript
99 lines
3.0 KiB
TypeScript
import { _decorator, CCClass, Component, sp } from "cc";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('HeroAnmComp')
|
|
export default class HeroAnmComp extends Component{
|
|
|
|
mixTime:number= 0.2;
|
|
|
|
private spine?: sp.Skeleton;
|
|
private _hasStop = true;
|
|
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('Idle', 'Attacking');
|
|
this._setMix('Idle', 'Taunt');
|
|
this._setMix('Idle', 'Walking');
|
|
this._setMix('Attacking', 'Idle');
|
|
this._setMix('Attacking', 'Walking');
|
|
this._setMix('Taunt', 'Walking');
|
|
this._setMix('Taunt', 'Idle');
|
|
|
|
spine.setCompleteListener((trackEntry) => {
|
|
var animationName = trackEntry.animation ? trackEntry.animation.name : "";
|
|
if (animationName === 'Attacking'||animationName==='Taunt'||animationName==='Hurt') {
|
|
this.spine!.clearTrack(1);
|
|
}
|
|
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;
|
|
}
|
|
|
|
// 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();
|
|
}
|
|
this.spine?.setAnimation(0, 'Walking', true);
|
|
this._hasStop = false;
|
|
}
|
|
atk () {
|
|
this.spine?.setAnimation(1, 'Attacking', false);
|
|
}
|
|
max () {
|
|
this.spine?.setAnimation(1, 'Taunt', false);
|
|
}
|
|
atked () {
|
|
this.spine?.setAnimation(1, 'Hurt', false);
|
|
}
|
|
idle () {
|
|
this.spine?.setToSetupPose();
|
|
this.spine?.setAnimation(0, 'Idle', true);
|
|
}
|
|
|
|
_setMix (anim1: string, anim2: string) {
|
|
this.spine?.setMix(anim1, anim2, this.mixTime);
|
|
this.spine?.setMix(anim2, anim1, this.mixTime);
|
|
}
|
|
} |