Actor.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. let library = require("../Library");
  2. let gameConfig = require("GameConfig");
  3. cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. gameStates: {
  7. default: null,
  8. type: cc.Node,
  9. serializable: true,
  10. },
  11. },
  12. onLoad () {
  13. this.gStatesScpt = this.gameStates.getComponent('GameStates');
  14. this.bDie = true;
  15. this.comeOutY = 5;
  16. this.hiddenY = -140;
  17. this.armatureDisplay = this.getComponent(dragonBones.ArmatureDisplay);
  18. this.blueArmatureDisplay = this.node.getChildByName('quantao_blue_ske').getComponent(dragonBones.ArmatureDisplay);
  19. this.redArmatureDisplay = this.node.getChildByName('quantao_ske').getComponent(dragonBones.ArmatureDisplay);
  20. //获取 Armatrue
  21. this.armature = this.armatureDisplay.armature();
  22. //添加动画监听
  23. this.armatureDisplay.addEventListener(dragonBones.EventObject.COMPLETE, this.animationEventHandler, this)
  24. },
  25. spawn(aMouse,appearDur,callback){
  26. let self = this;
  27. this.bDie = false;
  28. library.removeObj(this.gStatesScpt.hiddenMouseArr,this.node);
  29. this.gStatesScpt.appearMouseArr.push(this.node);
  30. this.armatureDisplay.playAnimation("idle2",1);
  31. //come out
  32. cc.tween(self.node)
  33. .to(0.1, { position: cc.v2(0,self.comeOutY)})
  34. .call(() =>
  35. {
  36. //delay to play
  37. self.scheduleOnce(function () {
  38. self.comeOutFinished(aMouse,callback);
  39. //come in
  40. cc.tween(self.node)
  41. .to(0.1, { position: cc.v2(0,self.hiddenY)})
  42. .start()
  43. },appearDur);
  44. })
  45. .start()
  46. },
  47. comeOutFinished(aMouse,callback)
  48. {
  49. callback(aMouse);
  50. // cc.log('comeOutFinished')
  51. },
  52. punch(bAi)
  53. {
  54. this.die();
  55. this.armatureDisplay.playAnimation("attack23",1);
  56. if(bAi)
  57. {
  58. this.redArmatureDisplay.playAnimation("attack2",1);
  59. }
  60. else
  61. {
  62. this.blueArmatureDisplay.playAnimation("attack2",1);
  63. }
  64. },
  65. leftPunch(bAi)
  66. {
  67. this.die();
  68. this.armatureDisplay.playAnimation("attack13",1);
  69. if(bAi)
  70. {
  71. this.redArmatureDisplay.playAnimation("attack1",1);
  72. }
  73. else
  74. {
  75. this.blueArmatureDisplay.playAnimation("attack1",1);
  76. }
  77. },
  78. rightPunch(bAi)
  79. {
  80. this.die();
  81. this.armatureDisplay.playAnimation("attack13",1);
  82. if(bAi)
  83. {
  84. this.redArmatureDisplay.playAnimation("attack1",1);
  85. }
  86. else
  87. {
  88. this.blueArmatureDisplay.playAnimation("attack1",1);
  89. }
  90. },
  91. cry(callback)
  92. {
  93. this.armatureDisplay.playAnimation("cry2",1);
  94. },
  95. animationEventHandler(event)
  96. {
  97. if (event.type === dragonBones.EventObject.COMPLETE)
  98. {
  99. if (event.animationState.name === "idle2")
  100. {
  101. // console.log("idle2 动作播放完毕!!!");
  102. //TODO:
  103. }
  104. else if (event.animationState.name === "attack13")
  105. {
  106. // console.log("attack13 直拳动作播放完毕!!!");
  107. }
  108. else if (event.animationState.name === "attack23")
  109. {
  110. // console.log("attack23 左勾拳/右勾拳动作播放完毕!!!");
  111. }
  112. else if (event.animationState.name === "attack2")
  113. {
  114. // console.log("cry2 哭动作播放完毕!!!");
  115. }
  116. }
  117. },
  118. die()
  119. {
  120. this.bDie = true;
  121. library.removeObj(this.gStatesScpt.appearMouseArr,this.node);
  122. this.gStatesScpt.hiddenMouseArr.push(this.node);
  123. }
  124. });