AI_tourist_Animation.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. var reGameStates = require('GameStates');
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. //人物类型
  6. AIType: {
  7. default: 1,
  8. type: cc.Integer,
  9. serializable: true,
  10. },
  11. FrontName: {
  12. default: 'front',
  13. visible: false,
  14. serializable: false,
  15. },
  16. BackName: {
  17. default: 'back',
  18. visible: false,
  19. serializable: false,
  20. },
  21. //是否循环
  22. isLoop: false,
  23. },
  24. onLoad: function () {
  25. this.dragonBones = this.node.getChildByName('dragonBones');
  26. //获取 ArmatureDisplay
  27. this._armatureDisPlay = this.dragonBones.getComponent(dragonBones.ArmatureDisplay)
  28. this._armatureDisPlay.armatureName = 'Tourist' + this.AIType;
  29. },
  30. // 切换当前是什么游客
  31. onSwitchTourist(_AIType) {
  32. this.AIType = _AIType;
  33. this._armatureDisPlay.armatureName = 'Tourist' + this.AIType;
  34. },
  35. switchAnimation: function (direction) {
  36. //动画执行方式二
  37. // cc.log('switchAnimation', direction);
  38. let loopValue = this.isLoop ? 0 : 1;
  39. switch (direction) {
  40. case reGameStates.moveType.none:
  41. // cc.log('reGameStates.moveType.none!!!!!!!!!!!!!!!');
  42. // if (this.IdleName)
  43. this._armatureDisPlay.timeScale = 0;
  44. break;
  45. case reGameStates.moveType.moveUp:
  46. this._armatureDisPlay.timeScale = 1;
  47. this.dragonBones.scaleX = 1;
  48. if (this.BackName)
  49. this._armatureDisPlay.playAnimation(this.BackName, loopValue);
  50. break;
  51. case reGameStates.moveType.moveRight:
  52. this._armatureDisPlay.timeScale = 1;
  53. this.dragonBones.scaleX = -1;
  54. if (this.BackName)
  55. this._armatureDisPlay.playAnimation(this.BackName, loopValue);
  56. break;
  57. case reGameStates.moveType.moveDown:
  58. this._armatureDisPlay.timeScale = 1;
  59. this.dragonBones.scaleX = 1;
  60. if (this.FrontName)
  61. this._armatureDisPlay.playAnimation(this.FrontName, loopValue);
  62. break;
  63. case reGameStates.moveType.moveLeft:
  64. this._armatureDisPlay.timeScale = 1;
  65. this.dragonBones.scaleX = -1;
  66. if (this.FrontName)
  67. this._armatureDisPlay.playAnimation(this.FrontName, loopValue);
  68. break;
  69. }
  70. },
  71. })