TrumpAnim.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. scaleX:1,
  5. AudioControllerNode: {
  6. default: null,
  7. type: cc.Node,
  8. serializable: true,
  9. },
  10. TalkingLabelNode:
  11. {
  12. default: null,
  13. type: cc.Node,
  14. serializable: true,
  15. }
  16. },
  17. start () {
  18. this.PunchedFaceNode = this.node.getChildByName("PunchedFace");
  19. this.LaughingFaceNode = this.node.getChildByName("LaughingFace");
  20. //动画
  21. this.PunchingAnimNode = this.node.getChildByName("PunchingAnim");
  22. this.armatureDisplay = this.PunchingAnimNode.getComponent(dragonBones.ArmatureDisplay);
  23. this.armature = this.armatureDisplay.armature();
  24. //添加动画事件监听
  25. this.armatureDisplay.addEventListener(dragonBones.EventObject.COMPLETE, this.animationEventHandler, this);
  26. this.armatureDisplay.addEventListener(dragonBones.EventObject.FRAME_EVENT, this.animationEventHandler_Enter, this);
  27. this.StartAnim();
  28. this.AudioControllerScp = this.AudioControllerNode.getComponent('AudioController');
  29. //川普say china
  30. this.sayChinaCount = 0;
  31. this.AudioControllerScp.playAudio('Game/Audios/ChinaThatThanMe.mp3',function () {
  32. //this.TalkChinaFinished(this);
  33. }.bind(this));
  34. },
  35. StartAnim()
  36. {
  37. this.FlapX();
  38. this.schedule(this.FlapX, 0.5, cc.macro.REPEAT_FOREVER);
  39. },
  40. StopAnim()
  41. {
  42. this.unschedule(this.FlapX);
  43. },
  44. Win(callback)
  45. {
  46. this.StopAnim();
  47. this.PunchedFaceNode.active=true;
  48. this.armature.animation.play("attack1", 1);
  49. this.AudioControllerScp.playAudio('Game/Audios/Hit.mp3',function(){
  50. this.PunchedFaceNode.active = false;
  51. callback();
  52. }.bind(this));
  53. },
  54. Fail(callback)
  55. {
  56. this.LaughingFaceNode.active = true;
  57. this.AudioControllerScp.playAudio('Game/Audios/Laughing.mp3',function(){
  58. this.LaughingFaceNode.active = false;
  59. callback();
  60. }.bind(this));
  61. },
  62. FlapX()
  63. {
  64. this.scaleX = -this.scaleX;
  65. this.node.setScale(this.scaleX,1);
  66. if(this.scaleX == 1)
  67. {
  68. this.TalkingLabelNode.setScale(1,1);
  69. }
  70. else
  71. {
  72. this.TalkingLabelNode.setScale(-1,1);
  73. }
  74. },
  75. animationEventHandler(event)
  76. {
  77. if (event.type === dragonBones.EventObject.COMPLETE) {
  78. //主角
  79. if (event.animationState.name === "attack1") {
  80. }
  81. }
  82. },
  83. animationEventHandler_Enter(event) {
  84. },
  85. TalkChinaFinished(self)
  86. {
  87. self.scheduleOnce(function() {
  88. self.AudioControllerScp.playAudio('Game/Audios/China.mp3',function () {
  89. self.TalkChinaFinished(self);
  90. });
  91. },Math.floor(Math.random()*20+1))
  92. // let rate = Math.floor(Math.random()*10);
  93. // console.log(rate)
  94. // //if(Boolean(Math.round(Math.random())))
  95. // if(rate<3)
  96. // {
  97. // self.scheduleOnce(function() {
  98. // self.AudioControllerScp.playAudio('Game/Audios/BelieveMe.mp3',function () {
  99. // self.TalkChinaFinished(self);
  100. // });
  101. // },Math.floor(Math.random()*10+1))
  102. // }
  103. // else
  104. // {
  105. // self.scheduleOnce(function() {
  106. // self.AudioControllerScp.playAudio('Game/Audios/China.mp3',function () {
  107. // self.TalkChinaFinished(self);
  108. // });
  109. // },Math.floor(Math.random()*10+1))
  110. // }
  111. }
  112. });