const { ccclass, property } = cc._decorator; @ccclass export default class NewClass extends cc.Component { @property(sp.Skeleton) spines: sp.Skeleton[] = []; index: number = 0; aniNames: string[]; aniIndex: number = 0; curSpineNode: cc.Node = null; onLoad() { cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this); cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyUp, this); } onKeyDown(event: cc.Event.EventKeyboard) { switch (event.keyCode) { case cc.macro.KEY.right: //选择人物 if (this.spines.length - 1 > this.index) this.index++ else this.index = 0; this.aniIndex = 0; console.log("spine role:" + this.spines[this.index].name); this.aniNames = []; let anis = this.spines[this.index].skeletonData.skeletonJson.animations; for (let i in anis) { this.aniNames.push(i); //console.log("Spine:" + i); } if (this.curSpineNode) { this.curSpineNode.scale = 1; } this.curSpineNode = this.spines[this.index].node; this.curSpineNode.scale = 1.2; break; case cc.macro.KEY.left: if (this.index > 0) this.index-- else this.index = this.spines.length - 1; this.aniIndex = 0; this.aniNames = []; console.log("spine role:" + this.spines[this.index].name); let anis2 = this.spines[this.index].skeletonData.skeletonJson.animations; for (let i in anis2) { this.aniNames.push(i); //console.log("Spine:" + i); } if (this.curSpineNode) { this.curSpineNode.scale = 1; } this.curSpineNode = this.spines[this.index].node; this.curSpineNode.scale = 1.2; break; case cc.macro.KEY.up: if (this.aniNames.length - 1 > this.aniIndex) this.aniIndex++; else this.aniIndex = 0; break; case cc.macro.KEY.down: if (this.aniIndex > 0) this.aniIndex-- else this.aniIndex = this.aniNames.length - 1; break; case cc.macro.KEY.space: if (this.aniNames != null) { console.log("ani name:" + this.aniNames[this.aniIndex]); //this.spines[this.index].clearTrack(0); this.spines[this.index].clearTracks(); //this.spines[this.index].invalidAnimationCache(); this.spines[this.index].setToSetupPose(); this.spines[this.index].setCompleteListener(()=>{ console.log("ani:"+this.aniNames[this.aniIndex]+"End"); }) this.spines[this.index].setAnimation(0, this.aniNames[this.aniIndex], false); console.log("Ani Duration:"+this.spines[this.index].findAnimation(this.aniNames[this.aniIndex]).duration) } else { console.log("no spine names"); } break; } } onKeyUp(event: cc.Event.EventKeyboard) { } onDestroy() { cc.systemEvent.off(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this); cc.systemEvent.off(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this); } } //{ // "obj": 0, // "evtId": 1, // "delay": 0, // "posx0": 185, // "posy0": -170, // "posx1": 185, // "posy1": -521, // "posDuration": 1, // "sameAct": [ // { // "obj": 0, // "evtId": 4, // "delay": 0, // "ani": "run_diaoluo", // "aniDuration": 0, // "aniLoop": 0, // "sameAct": [ // { // "obj": 0, // "evtId": 5, // "delay": 0.5, // "clip": "playDown_clip", // "volume": 1, // "desTime": 0, // "sameAct": [] // } // ] // } // ] //}