AI_tourist_Animation.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. var reGameStates = require('GameStates');
  2. //AI类型名称
  3. var AI_Type = ['TestGuy',
  4. 'Visitor',
  5. 'Tycoon',
  6. 'Office',
  7. 'Oligarchs',
  8. 'Nabobess']
  9. //动画名字
  10. var AI_Animation_Name = ['BankRight',
  11. 'FrontRight',
  12. 'FrontLeft',
  13. 'BankLeft',
  14. 'None'
  15. ]
  16. cc.Class({
  17. extends: cc.Component,
  18. properties: {
  19. //人物类型
  20. AIType: {
  21. default: reGameStates.AIType.TestGuy,
  22. type: cc.Enum(reGameStates.AIType),
  23. serializable: true,
  24. },
  25. RightName: {
  26. default: '',
  27. visible: false,
  28. serializable: false,
  29. },
  30. DownName: {
  31. default: '',
  32. visible: false,
  33. serializable: false,
  34. },
  35. LeftName: {
  36. default: '',
  37. visible: false,
  38. serializable: false,
  39. },
  40. UpName: {
  41. default: '',
  42. visible: false,
  43. serializable: false,
  44. },
  45. IdleName: {
  46. default: '',
  47. visible: false,
  48. serializable: false,
  49. },
  50. //是否循环
  51. isLoop: false,
  52. },
  53. onLoad: function () {
  54. //获取 ArmatureDisplay
  55. this._armatureDisPlay = this.node.getChildByName('dragonBones').getComponent(dragonBones.ArmatureDisplay)
  56. if (this._armatureDisPlay) {
  57. let aiTypeName = AI_Type[this.AIType];
  58. //获取 Armatrue
  59. this._armatureDisPlay.armatureName = aiTypeName;
  60. //动态设置名字
  61. this.RightName = aiTypeName + AI_Animation_Name[0];
  62. this.LeftName = aiTypeName + AI_Animation_Name[1];
  63. this.DownName = aiTypeName + AI_Animation_Name[2];
  64. this.UpName = aiTypeName + AI_Animation_Name[3];
  65. this._armature = this._armatureDisPlay.armature();
  66. } else {
  67. cc.warn('this._armatureDisPlay 为空。');
  68. }
  69. },
  70. // 切换当前是什么游客
  71. onSwitchTourist(_AIType) {
  72. this.AIType = _AIType;
  73. if (this._armatureDisPlay) {
  74. let aiTypeName = AI_Type[this.AIType];
  75. //获取 Armatrue
  76. this._armatureDisPlay.armatureName = aiTypeName;
  77. //动态设置名字
  78. this.RightName = aiTypeName + AI_Animation_Name[0];
  79. this.LeftName = aiTypeName + AI_Animation_Name[1];
  80. this.DownName = aiTypeName + AI_Animation_Name[2];
  81. this.UpName = aiTypeName + AI_Animation_Name[3];
  82. this._armature = this._armatureDisPlay.armature();
  83. } else {
  84. cc.warn('this._armatureDisPlay 为空。');
  85. }
  86. },
  87. switchAnimation: function (direction) {
  88. //动画执行方式二
  89. // cc.log('switchAnimation', direction);
  90. let loopValue = this.isLoop ? 0 : 1;
  91. switch (direction) {
  92. case reGameStates.moveType.none:
  93. // cc.log('reGameStates.moveType.none!!!!!!!!!!!!!!!');
  94. // if (this.IdleName)
  95. this._armatureDisPlay.playAnimation(this.IdleName, 1);
  96. break;
  97. case reGameStates.moveType.moveUp:
  98. if (this.UpName)
  99. this._armatureDisPlay.playAnimation(this.UpName, loopValue);
  100. break;
  101. case reGameStates.moveType.moveRight:
  102. if (this.RightName)
  103. this._armatureDisPlay.playAnimation(this.RightName, loopValue);
  104. break;
  105. case reGameStates.moveType.moveDown:
  106. if (this.DownName)
  107. this._armatureDisPlay.playAnimation(this.DownName, loopValue);
  108. break;
  109. case reGameStates.moveType.moveLeft:
  110. if (this.LeftName)
  111. this._armatureDisPlay.playAnimation(this.LeftName, loopValue);
  112. break;
  113. }
  114. },
  115. })