手动控制spine 动画
This commit is contained in:
@@ -4,9 +4,7 @@
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-08-04 15:26:38
|
||||
*/
|
||||
import { sp, _decorator } from "cc";
|
||||
import AnimatorSpine from "../../../../../extensions/oops-plugin-framework/assets/libs/animator/AnimatorSpine";
|
||||
import Charactor, { CharactorDirection } from "../../map/view/map/charactor/Charactor";
|
||||
import { sp, _decorator ,Component} from "cc";
|
||||
|
||||
const { ccclass, property, requireComponent, disallowMultiple } = _decorator;
|
||||
|
||||
@@ -16,24 +14,28 @@ const { ccclass, property, requireComponent, disallowMultiple } = _decorator;
|
||||
@ccclass
|
||||
@disallowMultiple
|
||||
@requireComponent(sp.Skeleton)
|
||||
export default class RoleSpineAnimator extends AnimatorSpine {
|
||||
private charactor!: Charactor;
|
||||
private dir: CharactorDirection = CharactorDirection.bottom;
|
||||
export default class RoleSpineAnimator extends Component {
|
||||
private animName: string = "idle";
|
||||
private loop: boolean = true;
|
||||
|
||||
start() {
|
||||
this.charactor = this.node.parent!.getComponent(Charactor)!;
|
||||
super.start();
|
||||
console.log("RoleSpineAnimator start");
|
||||
this.playAnimation(this.animName, this.loop);
|
||||
}
|
||||
|
||||
lateUpdate(dt: number) {
|
||||
if (this.dir != this.charactor.direction) {
|
||||
this.dir = this.charactor.direction;
|
||||
this.playAnimation(this.animName, this.loop);
|
||||
}
|
||||
this.playAnimation(this.animName, this.loop);
|
||||
|
||||
}
|
||||
|
||||
play(animName: string, loop: boolean) {
|
||||
if (animName) {
|
||||
this.animName = animName;
|
||||
this.loop = loop;
|
||||
}
|
||||
else {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 播放动画
|
||||
* @override
|
||||
@@ -44,29 +46,9 @@ export default class RoleSpineAnimator extends AnimatorSpine {
|
||||
if (animName) {
|
||||
this.animName = animName;
|
||||
this.loop = loop;
|
||||
|
||||
// animName = `huaxian/${this.getDirection(this.charactor.direction)}${animName}`;
|
||||
this._spine.setAnimation(0, animName, loop);
|
||||
}
|
||||
else {
|
||||
this._spine.clearTrack(0);
|
||||
}
|
||||
}
|
||||
|
||||
private getDirection(dir: CharactorDirection): string {
|
||||
let dirName = "";
|
||||
if (dir == CharactorDirection.up) {
|
||||
dirName = "back";
|
||||
}
|
||||
else if (dir == CharactorDirection.bottom) {
|
||||
dirName = "positive";
|
||||
}
|
||||
else if (dir == CharactorDirection.left || dir == CharactorDirection.left_up || dir == CharactorDirection.left_bottom) {
|
||||
dirName = "side";
|
||||
}
|
||||
else if (dir == CharactorDirection.right || dir == CharactorDirection.right_up || dir == CharactorDirection.right_bottom) {
|
||||
dirName = "side";
|
||||
}
|
||||
return dirName;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user