GameLucyController.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. GameStates: {
  5. default: null,
  6. type: cc.Node,
  7. serializable: true,
  8. },
  9. ChiVoice: {
  10. default: null,
  11. type: cc.AudioClip,
  12. serializable: true,
  13. },
  14. },
  15. start () {
  16. this.GirlAnimations = this.GameStates.getComponent('GameStates').GirlAnimations;
  17. //获取 ArmatureDisplay
  18. this._armatureDisPlay = this.node.getComponent(dragonBones.ArmatureDisplay);
  19. this._armature = this._armatureDisPlay.armature();
  20. //Hide HeadPhone
  21. // this.slot = this._armature.getSlot('erji');
  22. // this.slot.visible = false;
  23. //Add Animation Callback
  24. this._armatureDisPlay.addEventListener(dragonBones.EventObject.START, this.animationEventHandler, this);
  25. this._armatureDisPlay.addEventListener(dragonBones.EventObject.COMPLETE, this.animationEventHandler, this);
  26. // Is playing any animation
  27. this.BPlayingAnimation = false;
  28. // 重复次数
  29. let repeat = cc.REPEAT_FOREVER;
  30. // 以秒为单位的时间间隔
  31. let interval = 10;
  32. // 开始延时
  33. let delay = 0;
  34. this.schedule(function()
  35. {
  36. if(!this.BPlayingAnimation)
  37. {
  38. // let RandNum = this.Rand(0,100);
  39. // if(RandNum>20)
  40. // {
  41. // this.Idle( 2);
  42. // }
  43. // else
  44. // {
  45. // this.Happy( 1);
  46. // }
  47. let RandBool = this.Rand(0,1);
  48. let RandNum = this.Rand(0,this.GirlAnimations.length-1);
  49. let AnimName = this.GirlAnimations[0,RandNum];
  50. if(RandBool==0)
  51. {
  52. if(AnimName == 'Idle')
  53. {
  54. this.Idle( 1);
  55. let RandNum100 = this.Rand(0,100);
  56. if(RandNum100<20)
  57. {
  58. cc.audioEngine.playEffect(this.ChiVoice, false);
  59. }
  60. }
  61. }
  62. }
  63. }, interval, repeat, delay);
  64. },
  65. Idle(PlayTimes){
  66. if(this.GirlAnimations.indexOf('Idle')==-1) return;
  67. this._armatureDisPlay.timeScale =2;
  68. this._armatureDisPlay.playAnimation('Idle', PlayTimes);
  69. },
  70. Happy(PlayTimes){
  71. if(this.GirlAnimations.indexOf('Happy')==-1) return;
  72. this._armatureDisPlay.timeScale =2;
  73. this._armatureDisPlay.playAnimation('Happy',PlayTimes);
  74. },
  75. Shy(){
  76. if(this.GirlAnimations.indexOf('Shy')==-1) return;
  77. if(this.BPlayingAnimation) return;
  78. this._armatureDisPlay.timeScale =2;
  79. this._armatureDisPlay.playAnimation('Shy', 1);
  80. },
  81. Angry(){
  82. if(this.GirlAnimations.indexOf('Angry')==-1) return;
  83. if(this.BPlayingAnimation) return;
  84. this._armatureDisPlay.timeScale =2;
  85. this._armatureDisPlay.playAnimation('Angry', 1);
  86. },
  87. animationEventHandler: function animationEventHandler(event) {
  88. if (event.type == dragonBones.EventObject.START) {
  89. this.BPlayingAnimation = true;
  90. // cc.log('START='+this._armatureDisPlay.animationName);
  91. } else if (event.type == dragonBones.EventObject.COMPLETE) {
  92. // cc.log('COMPLETE='+this._armatureDisPlay.animationName);
  93. this.BPlayingAnimation = false;
  94. }
  95. },
  96. Rand(star, end){
  97. let random = Math.floor(Math.random()*(end-star+1)+star);
  98. return random;
  99. },
  100. });