CEffectArray.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. function CEffectArray(iXPos, iYPos, oSprite, oParentContainer) {
  2. var _pStartPos;
  3. var _oEffectArrow;
  4. var _oTextEffect;
  5. var _oContainer;
  6. var _oParentContainer;
  7. var _iStartRegX;
  8. this._init = function (iXPos, iYPos, oSprite, oParentContainer) {
  9. _pStartPos = {x: iXPos, y: iYPos};
  10. _oContainer = new createjs.Container();
  11. _oContainer.x = iXPos;
  12. _oContainer.y = iYPos;
  13. _oParentContainer = oParentContainer;
  14. _oParentContainer.addChild(_oContainer);
  15. var fAnimSpeed = SPEED_EFFECT_ARROW / FPS;
  16. var oData = {
  17. images: [oSprite],
  18. // width, height & registration point of each sprite
  19. frames: {width: oSprite.width / 10, height: oSprite.height / 2, regX: (oSprite.width / 2) / 10, regY: (oSprite.height / 2) / 2},
  20. animations: {
  21. normal: [0, 19, "reverse", fAnimSpeed],
  22. reverse: {
  23. frames: [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],
  24. speed: fAnimSpeed
  25. }
  26. }
  27. };
  28. var oSpriteSheet = new createjs.SpriteSheet(oData);
  29. _oEffectArrow = createSprite(oSpriteSheet, "normal", (oSprite.width / 2) / 10, (oSprite.height / 2) / 2, oSprite.width / 10, oSprite.height / 2);
  30. _oEffectArrow.y = -30;
  31. _iStartRegX = _oEffectArrow.regX = (oSprite.width / 2) / 10;
  32. this.stopAnimation();
  33. _oContainer.addChild(_oEffectArrow);
  34. this.createTextEffect(oSprite);
  35. };
  36. this.getX = function () {
  37. return _oEffectArrow.x;
  38. };
  39. this.getY = function () {
  40. return _oEffectArrow.y;
  41. };
  42. this.getStartPos = function () {
  43. return _pStartPos;
  44. };
  45. this.playAnimation = function () {
  46. _oEffectArrow.play();
  47. };
  48. this.stopAnimation = function () {
  49. _oEffectArrow.stop();
  50. };
  51. this.getStoppedFrame = function () {
  52. return _oEffectArrow.currentFrame * _oEffectArrow.scaleX;
  53. };
  54. this.removeAllEventListeners = function () {
  55. _oEffectArrow.removeAllEventListeners();
  56. };
  57. this.setPosition = function (iXPos, iYPos) {
  58. _oContainer.x = iXPos;
  59. _oContainer.y = iYPos;
  60. };
  61. this.setVisible = function (bVal) {
  62. _oContainer.visible = bVal;
  63. };
  64. this.getScaleX = function () {
  65. return _oEffectArrow.scaleX;
  66. };
  67. this.createTextEffect = function (oSprite) {
  68. _oTextEffect = new createjs.Text(TEXT_EFFECT, 36 + "px " + FONT_GAME, "#ffffff");
  69. _oTextEffect.textAlign = "center";
  70. _oTextEffect.textBaseline = "middle";
  71. _oTextEffect.x = -_iStartRegX * 1.6;
  72. _oTextEffect.y = (oSprite.height / 4);
  73. _oContainer.addChild(_oTextEffect);
  74. };
  75. this.animArrow = function () {
  76. var oParent = this;
  77. _oEffectArrow.gotoAndPlay("normal");
  78. this.onFinishAnimation(function () {
  79. _oEffectArrow.gotoAndPlay("reverse");
  80. _oEffectArrow.removeAllEventListeners();
  81. oParent.onFinishAnimation(function () {
  82. _oEffectArrow.scaleX *= -1;
  83. if (_oEffectArrow.scaleX === -1) {
  84. _oEffectArrow.regX = -_iStartRegX * 2 - 14;
  85. } else {
  86. _oEffectArrow.regX = _iStartRegX;
  87. }
  88. _oEffectArrow.removeAllEventListeners();
  89. oParent.animArrow();
  90. });
  91. });
  92. };
  93. this.changeState = function (szState) {
  94. var oParent = this;
  95. _oEffectArrow.gotoAndPlay(szState);
  96. this.onFinishAnimation(function () {
  97. oParent.loopAnimArray();
  98. });
  99. };
  100. this.animFade = function (fAlpha) {
  101. createjs.Tween.get(_oEffectArrow).to({alpha: fAlpha}, 250, createjs.Ease.circleOut).call(function () {
  102. if (fAlpha === 0) {
  103. _oContainer.visible = false;
  104. }
  105. });
  106. };
  107. this.onFinishAnimation = function (oFunc) {
  108. _oEffectArrow.on("animationend", function () {
  109. oFunc();
  110. });
  111. };
  112. this.unload = function () {
  113. _oEffectArrow.removeAllEventListeners();
  114. _oParentContainer.removeChild(_oContainer);
  115. };
  116. this._init(iXPos, iYPos, oSprite, oParentContainer);
  117. return this;
  118. }