动画替换完成

This commit is contained in:
pan@work
2024-11-29 16:45:32 +08:00
parent 7c80b3b191
commit 935d3f1185
10 changed files with 257 additions and 224 deletions

View File

@@ -93,7 +93,7 @@ export class SingletonModuleComp extends ecs.Comp {
gems:0,
energy:0,
},
fight_heros:[9001,9001],
fight_heros:[9001,],
items:{
1001:0,
1002:0,

View File

@@ -28,7 +28,7 @@ export enum BoxSet {
MONSTER_START = 360,
END_POINT = 360,
//游戏地平线
GAME_LINE = 0,
GAME_LINE = 10,
CSKILL_X = 320,
CSKILL_Y = 400,
//攻击距离

View File

@@ -1,7 +1,7 @@
export const HeroInfo = {
9001: {
uuid:9001,name: "骑士·白",path:"k1",type:1,hp: 20, hp_up:10,def:10,def_up:1,ap:20,ap_up:2,atp:1,vun:0,crit:20,crit_add:0,dodge:0,dis:100,a_cd:1,
uuid:9001,name: "骑士·白",path:"k1",type:1,hp: 200, hp_up:10,def:10,def_up:1,ap:20,ap_up:2,atp:1,vun:0,crit:20,crit_add:0,dodge:0,dis:100,a_cd:1,
lvexp:2,slvexp:2, speed: 100,aep:1,uaep:1,dep:10,sk1:[9001,9001,9001,9001,9001],sk2: [2002,2002,2002,2002,2002],pw:0,pwm:15,pws:1,
akr:[10,20,30,40,50],akc:[1,1,1,1,1],uar:[10,20,30,40,50],uac:[1,1,1,1,1],dgr:[10,20,30,40,50],dgc:[1,1,1,1,1],crr:[10,20,30,40,50],crc:[1,1,1,1,1],
abh:0,abc:0,uabh:0,uabc:0,cbh:0,cbc:0,aua:0,auc:0,uaua:0,uauc:0,cua:0,cuc:0,wp:1001,arm:2001,ring:3001,shoes:4001,

View File

@@ -54,7 +54,7 @@ export class Hero extends ecs.Entity {
this.addComponents<ecs.Comp>( MonModelComp);
}
var path = "game/hero/"+smc.heros[uuid].path;
var path = "game/heros/"+smc.heros[uuid].path;
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);

View File

@@ -1,50 +1,99 @@
/*
* @Author: dgflash
* @Date: 2022-08-04 15:08:35
* @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 { _decorator, CCClass, Component, sp } from "cc";
const { ccclass, property } = _decorator;
const { ccclass, property, requireComponent, disallowMultiple } = _decorator;
@ccclass('HeroAnmComp')
export default class HeroAnmComp extends Component{
/**
* Spine状态机组件主状态机trackIndex为0
*/
@ccclass
@disallowMultiple
@requireComponent(sp.Skeleton)
export default class HeroAnmComp extends AnimatorSpine {
mixTime:number= 0.2;
private animName: string = "Idle";
private loop: boolean = true;
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');
start() {
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);
super.start();
this._hasStop = false;
}
lateUpdate(dt: number) {
// OPTIONS
toggleDebugSlots () {
this.spine!.debugSlots = !this.spine?.debugSlots;
}
/**
* 播放动画
* @override
* @param animName 动画名
* @param loop 是否循环播放
*/
protected playAnimation(animName: string, loop: boolean) {
if (animName) {
this.animName = animName;
this.loop = loop;
toggleDebugBones () {
this.spine!.debugBones = !this.spine?.debugBones;
}
this._spine.setAnimation(0, animName, loop);
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.clearTrack(0);
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);
}
}

View File

@@ -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;
/**
* 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();

View File

@@ -455,6 +455,7 @@ export class HeroViewComp extends CCComp {
//使用max_skill
handle_skill(skill:number){
this.as.atk()
this.at = 0;
this.tooltip(3,smc.skills[skill].name,skill);
switch (smc.skills[skill].tg) {
@@ -673,6 +674,7 @@ export class HeroViewComp extends CCComp {
let pos =v3(0,30);
node.setPosition(pos)
node.parent = this.node;
// this.as.atked();
this.atked_count++;
this.exp_add(this.uaep)
}

View File

@@ -30,24 +30,7 @@ export class CardControllerComp extends CCComp {
}
show_info(uuid:number,type:number){
// console.log("show_info",uuid)
let node =this.node.getChildByName("item_box")
if(type == 2){
smc.vmdata.item_box.info = smc.sitems[uuid].info
smc.vmdata.item_box.name = smc.sitems[uuid].name
smc.vmdata.item_box.skillcd = smc.sitems[uuid].cd
smc.vmdata.item_box.skillsd = smc.sitems[uuid].sd
smc.vmdata.item_box.atk = smc.sitems[uuid].atk
smc.vmdata.item_box.hp = smc.sitems[uuid].hp
smc.vmdata.item_box.shield = smc.sitems[uuid].shield
node.active=true
if(smc.sitems[uuid].shield > 0){
node.getChildByName("data").getChildByName("shield").active=true
}
if(smc.sitems[uuid].hp > 0){
node.getChildByName("data").getChildByName("hp").active=true
}
}
console.log("show_info",uuid)
}
protected update(dt: number): void {
@@ -82,7 +65,6 @@ export class CardControllerComp extends CCComp {
this.node.getChildByName("bar").getChildByName("mission_btn").getChildByName("bg").active=false
this.node.getChildByName("bar").getChildByName("hero_btn").getChildByName("bg").active=false
this.node.getChildByName("bar").getChildByName("home_btn").getChildByName("bg").active=true
}
to_hero(){
this.node.getChildByName("mission_home").active=false
@@ -93,12 +75,6 @@ export class CardControllerComp extends CCComp {
this.node.getChildByName("bar").getChildByName("home_btn").getChildByName("bg").active=false
}
item_info_show(){
this.node.getChildByName("item_info").setScale(1,1,1)
}
item_info_hide(){
this.node.getChildByName("item_info").setScale(0,0,1)
}
/** 视图对象通过 ecs.Entity.remove(ControllerComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();