Charactor.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. PlayerStatesNode: {
  5. default: null,
  6. type: cc.Node,
  7. serializable: true,
  8. },
  9. },
  10. onLoad () {
  11. this.PlayerStatesScp = this.PlayerStatesNode.getComponent('PlayerStates');
  12. this.anim = this.node.getComponent(sp.Skeleton);
  13. this.anim.setCompleteListener(this.SpineEventCallback);
  14. },
  15. Run(lv)
  16. {
  17. if(lv == this.PlayerStatesScp.state) return;
  18. this.PlayerStatesScp.state = lv;
  19. switch (lv) {
  20. case 1:
  21. //this.anim.animation = 'run';// 要播放的动画名称【必填】
  22. //this.anim.loop = true;// 是否循环
  23. this.runAnim = this.anim.setAnimation(0, 'Run1', true);
  24. break;
  25. case 2:
  26. //this.anim.animation = 'run';// 要播放的动画名称【必填】
  27. //this.anim.loop = true;// 是否循环
  28. this.runAnim = this.anim.setAnimation(0, 'Run2', true);
  29. break;
  30. case 3:
  31. //this.anim.animation = 'run';// 要播放的动画名称【必填】
  32. //this.anim.loop = true;// 是否循环
  33. this.runAnim = this.anim.setAnimation(0, 'Run3', true);
  34. break;
  35. default:
  36. break;
  37. }
  38. },
  39. Idel()
  40. {
  41. if(this.PlayerStatesScp.state == this.PlayerStatesScp.stateTag.idle) return;
  42. this.PlayerStatesScp.state = this.PlayerStatesScp.stateTag.idle;
  43. this.runAnim = this.anim.setAnimation(0, 'idle', true);
  44. },
  45. SpineEventCallback(trackEntry, loopCount)
  46. {
  47. if (trackEntry.animation.name === 'Run1') {
  48. //cc.log('Run1结束')
  49. }
  50. }
  51. });