CBall.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. function CBall(iXPos, iYPos, oSprite, oPhysics, oParentContainer) {
  2. var _oBall;
  3. var _oBallRef;
  4. var _oParentContainer;
  5. var _oPhysics;
  6. var _oShadow;
  7. var _oContainer;
  8. var _fStartShadowPos = null;
  9. var _fScale = 36;
  10. var _oTween = null;
  11. var _bPlayedSound = false;
  12. this._init = function (iXPos, iYPos, oSprite) {
  13. _oContainer = new createjs.Container();
  14. _oParentContainer.addChild(_oContainer);
  15. _oBall = createBitmap(oSprite);
  16. _oBall.x = iXPos;
  17. _oBall.y = iYPos;
  18. _oBall.regX = oSprite.width * 0.5;
  19. _oBall.regY = oSprite.height * 0.5;
  20. var oSpriteReflect = s_oSpriteLibrary.getSprite("ball_ref");
  21. _oBallRef = createBitmap(oSpriteReflect);
  22. _oBallRef.x = iXPos;
  23. _oBallRef.y = iYPos;
  24. _oBallRef.regX = oSpriteReflect.width * 0.5;
  25. _oBallRef.regY = -oSpriteReflect.height * 0.5 + 15;
  26. _oBallRef.alpha = 0.75;
  27. var oSpriteShadow = s_oSpriteLibrary.getSprite("ball_shadow");
  28. _oShadow = createBitmap(oSpriteShadow);
  29. _oShadow.x = iXPos;
  30. _oShadow.y = iYPos;
  31. _oShadow.regX = oSpriteShadow.width * 0.5;
  32. _oShadow.regY = oSpriteShadow.height * 0.5;
  33. _oContainer.addChild(_oShadow, _oBall, _oBallRef);
  34. };
  35. this.unload = function () {
  36. _oBall.removeAllEventListeners();
  37. _oParentContainer.removeChild(_oBall);
  38. };
  39. this.setVisible = function (bVisible) {
  40. _oContainer.visible = bVisible;
  41. };
  42. this.startPosShadowY = function (fYPos) {
  43. _fStartShadowPos = fYPos;
  44. };
  45. this.getStartShadowYPos = function () {
  46. return _fStartShadowPos;
  47. };
  48. this.tweenFade = function (fVal, iTime, iWait) {
  49. _oTween = createjs.Tween.get(_oContainer).wait(iWait).to({alpha: fVal}, iTime).call(function () {
  50. _oTween = null;
  51. });
  52. };
  53. this.playSound = function () {
  54. if (_bPlayedSound) {
  55. return;
  56. }
  57. playSound("ball_crash", 1, false);
  58. _bPlayedSound = true;
  59. };
  60. this.setPlayedSound = function (bVal) {
  61. _bPlayedSound = bVal;
  62. };
  63. this.animFade = function (fAlpha) {
  64. createjs.Tween.get(_oContainer).to({alpha: fAlpha}, 250, createjs.Ease.circleOut).call(function () {
  65. if (fAlpha === 0) {
  66. _oContainer.visible = false;
  67. _oContainer.alpha = 1;
  68. s_oGame.resetBallPosition();
  69. }
  70. });
  71. };
  72. this.setPositionShadow = function (iX, iY) {
  73. _oShadow.x = iX;
  74. _oShadow.y = iY;
  75. };
  76. this.setPosition = function (iXPos, iYPos) {
  77. _oBallRef.x = _oBall.x = iXPos;
  78. _oBallRef.y = _oBall.y = iYPos;
  79. };
  80. this.getPhysics = function () {
  81. return _oPhysics;
  82. };
  83. this.setAngle = function (iAngle) {
  84. _oBallRef.rotation = _oBall.rotation = iAngle;
  85. };
  86. this.getX = function () {
  87. return _oBall.x;
  88. };
  89. this.getY = function () {
  90. return _oBall.y;
  91. };
  92. this.getStartScale = function () {
  93. return _fScale;
  94. };
  95. this.scale = function (fValue) {
  96. _oBallRef.scaleX = _oBall.scaleX = fValue;
  97. _oBallRef.scaleY = _oBall.scaleY = fValue;
  98. };
  99. this.scaleShadow = function (fScale) {
  100. if (fScale > 0.08) {
  101. _oShadow.scaleX = fScale;
  102. _oShadow.scaleY = fScale;
  103. } else {
  104. _oShadow.scaleX = 0.08;
  105. _oShadow.scaleY = 0.08;
  106. }
  107. };
  108. this.setAlphaByHeight = function (fHeight) {
  109. _oShadow.alpha = fHeight;
  110. };
  111. this.getScale = function () {
  112. return _oBall.scaleX;
  113. };
  114. this.getObject = function () {
  115. return _oContainer;
  116. };
  117. this.getDepthPos = function () {
  118. return _oPhysics.position.y;
  119. };
  120. _oPhysics = oPhysics;
  121. _oParentContainer = oParentContainer;
  122. this._init(iXPos, iYPos, oSprite);
  123. return this;
  124. }