This commit is contained in:
2024-07-21 22:39:39 +08:00
parent 883261dac6
commit 064b6bf1ae
14 changed files with 348 additions and 43 deletions

View File

@@ -5,6 +5,7 @@
* @LastEditTime: 2022-08-04 15:26:38
*/
import { sp, _decorator ,Component} from "cc";
import { smc } from "../../common/SingletonModuleComp";
const { ccclass, property, requireComponent, disallowMultiple } = _decorator;
@@ -17,21 +18,72 @@ const { ccclass, property, requireComponent, disallowMultiple } = _decorator;
export default class RoleSpineAnimator extends Component {
private animName: string = "idle";
private loop: boolean = true;
private spine!: sp.Skeleton;
start() {
console.log("RoleSpineAnimator start");
this.playAnimation(this.animName, this.loop);
this.spine = this.getComponent(sp.Skeleton)!;
console.log("RoleSpineAnimator start smc.heros",smc.heros);
let heros=smc.heros
if(heros.length>0){
/**
* 取第一个heros
*/
this.spine.setSkin(heros[0])
console.log("RoleSpineAnimator setSkin", heros[0]);
switch (heros[0]) {
case 'war':
this.spine.setAnimation(0, 'idle', true)
break;
case 'magic':
this.spine.setAnimation(0, 'idle', true)
break;
case 'heath':
this.spine.setAnimation(0, 'idle', true)
break;
default:
this.spine.setAnimation(0, 'idle', true)
break;
}
//移除smc.heros[0],heros key 重新取
heros.splice(0,1)
smc.heros=heros
}else if(smc.monsters.length>0){
this.spine.setSkin(smc.monsters[0])
console.log("RoleSpineAnimator setSkin", smc.monsters[0]);
switch (smc.monsters[0]) {
case 'war':
this.spine.setAnimation(0, 'idle', true)
break;
case 'magic':
this.spine.setAnimation(0, 'idle', true)
break;
case 'heath':
this.spine.setAnimation(0, 'idle', true)
break;
default:
this.spine.setAnimation(0, 'idle', true)
break;
}
}
}
lateUpdate(dt: number) {
this.playAnimation(this.animName, this.loop);
}
getRandomInt(min: number, max: number): number {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
play(animName: string, loop: boolean) {
if (animName) {
this.animName = animName;
this.loop = loop;
this.spine.setAnimation(0, this.animName, this.loop);
}
else {
}
@@ -43,9 +95,12 @@ export default class RoleSpineAnimator extends Component {
* @param loop 是否循环播放
*/
protected playAnimation(animName: string, loop: boolean) {
console.log("RoleSpineAnimator playAnimation");
if (animName) {
console.log("RoleSpineAnimator playAnimation animName", animName);
this.animName = animName;
this.loop = loop;
this.spine.setAnimation(0, this.animName, this.loop);
}
else {
}