PopupSound.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /**
  2. * Created by admin on 2018-06-07.
  3. */
  4. gc.PopupSound = function () {
  5. PIXI.Container.call(this);
  6. this.bgBlack = GraphicManager.drawRect(gc.width, gc.height, "0X000000");
  7. this.bgBlack.alpha = 0.7;
  8. this.bg = new PIXI.Sprite.fromFrame("popup_bg_sound1.png");
  9. this.bg.anchor.set(0.5);
  10. this.btnClose = new PIXI.Sprite.fromFrame("popup_btn_close.png");
  11. this.btnClose.anchor.set(0.5);
  12. bm.buttonEvent(this.btnClose, true, null, null, this.closeSoundPopup.bind(this));
  13. this.btnBgm = new PIXI.Sprite.fromFrame("popup_btn_sound1_off.png");
  14. this.btnBgm.anchor.set(0.5);
  15. bm.buttonEvent(this.btnBgm, true, null, null, this.setBgm.bind(this));
  16. this.btnFx = new PIXI.Sprite.fromFrame("popup_btn_sound2_off.png");
  17. this.btnFx.anchor.set(0.5);
  18. bm.buttonEvent(this.btnFx, true, null, null, this.setFx.bind(this));
  19. this.btnRestart = new PIXI.Sprite.fromFrame("popup_btn_restart.png");
  20. this.btnRestart.anchor.set(0.5);
  21. bm.buttonEvent(this.btnRestart, true, null, null, (function () {
  22. // restartGame();
  23. this.setInteractive(false);
  24. GD.stage.removeChild(this);
  25. onGame();
  26. }).bind(this));
  27. };
  28. gc.PopupSound.constructor = gc.PopupSound;
  29. gc.PopupSound.prototype = Object.create(PIXI.Container.prototype);
  30. gc.PopupSound.prototype.onSoundPopup = function () {
  31. this.reset();
  32. this.setBgImg();
  33. this.setButtonImage();
  34. this.setPosition();
  35. this.bg.addChild(this.btnBgm);
  36. this.bg.addChild(this.btnFx);
  37. this.bg.addChild(this.btnClose);
  38. this.addChild(this.bgBlack);
  39. this.addChild(this.bg);
  40. if(gc.game) {
  41. this.bg.addChild(this.btnRestart);
  42. gc.game.pause();
  43. }
  44. var time = 0.1;
  45. TweenMax.fromTo(this.bg.scale, time, {x:0, y:0}, {x:1.05, y:1.05, onComplete:(function () {
  46. TweenMax.to(this.bg.scale, time/2, {x:1, y:1, onComplete:(function () {
  47. this.bg.scale.x = 1;
  48. this.bg.scale.y = 1;
  49. this.setInteractive(true);
  50. }).bind(this)});
  51. }).bind(this)});
  52. GD.stage.addChild(this);
  53. };
  54. gc.PopupSound.prototype.closeSoundPopup = function () {
  55. gc.pauseGame = false;
  56. var time = 0.1;
  57. this.bg.scale.x = 1;
  58. this.bg.scale.y = 1;
  59. TweenMax.to(this.bg.scale, time, {x:1.1, y:1.1, onComplete:(function () {
  60. TweenMax.to(this.bg.scale, time/2, {x:0, y:0, onComplete:(function () {
  61. GD.stage.removeChild(this);
  62. if(gc.intro) {
  63. gc.intro.setInteractive(true);
  64. }
  65. else if(gc.game) {
  66. gc.game.resume();
  67. }
  68. }).bind(this)});
  69. }).bind(this)});
  70. };
  71. //배경 이미지
  72. gc.PopupSound.prototype.setBgImg = function () {
  73. if(gc.intro) this.bg.texture = PIXI.Texture.fromFrame("popup_bg_sound2.png");
  74. else if(gc.game) this.bg.texture = PIXI.Texture.fromFrame("popup_bg_sound1.png");
  75. this.bg.scale.x = 1;
  76. this.bg.scale.y = 1;
  77. };
  78. //버튼 이미지 활성화 설정
  79. gc.PopupSound.prototype.setButtonImage = function () {
  80. if(gc.onBgm) this.btnBgm.texture = PIXI.Texture.fromFrame("popup_btn_sound1_on.png");
  81. else this.btnBgm.texture = PIXI.Texture.fromFrame("popup_btn_sound1_off.png");
  82. if(gc.onFx) this.btnFx.texture = PIXI.Texture.fromFrame("popup_btn_sound2_on.png");
  83. else this.btnFx.texture = PIXI.Texture.fromFrame("popup_btn_sound2_off.png");
  84. };
  85. //좌표 설정
  86. gc.PopupSound.prototype.setPosition = function () {
  87. this.bg.x = gc.width/2;
  88. this.bg.y = gc.height/2;
  89. var gap = 60;
  90. this.btnClose.x = this.bg.width/2 - 50;
  91. this.btnClose.y = -this.bg.height/2 + gap;
  92. if(gc.intro) {
  93. gap = this.btnBgm.height + 40;
  94. this.btnBgm.y = -this.bg.height/2 + 190;
  95. this.btnFx.y = this.btnBgm.y + gap;
  96. this.btnRestart.y = this.btnFx.y + gap;
  97. }
  98. else if(gc.game) {
  99. gap = this.btnBgm.height + 10;
  100. this.btnBgm.y = -this.bg.height/2 + 185;
  101. this.btnFx.y = this.btnBgm.y + gap;
  102. gap += 30;
  103. this.btnRestart.y = this.btnFx.y + gap;
  104. }
  105. this.btnBgm.x = 0;
  106. this.btnFx.x = this.btnBgm.x;
  107. this.btnRestart.x = this.btnBgm.x;
  108. };
  109. //배경음 설정
  110. gc.PopupSound.prototype.setBgm = function () {
  111. gc.onBgm = !gc.onBgm;
  112. console.log("gc.onBgm", gc.onBgm);
  113. // if(!gc.onBgm) GD.soundMute("sound_bgm_mini");
  114. // else GD.soundUnMute("sound_bgm_mini");
  115. if(gc.game) {
  116. if(!gc.onBgm) GD.soundStop("sound_bgm_mini");
  117. else GD.soundPlay("sound_bgm_mini");
  118. }
  119. this.setButtonImage();
  120. };
  121. //효과음 설정
  122. gc.PopupSound.prototype.setFx = function () {
  123. gc.onFx = !gc.onFx;
  124. console.log("gc.onFx", gc.onFx);
  125. this.setButtonImage();
  126. };
  127. gc.PopupSound.prototype.setInteractive = function (bool) {
  128. this.btnClose.interactive = bool;
  129. this.btnBgm.interactive = bool;
  130. this.btnFx.interactive = bool;
  131. this.btnRestart.interactive = bool;
  132. };
  133. gc.PopupSound.prototype.reset = function () {
  134. this.removeChildren();
  135. this.bg.removeChildren();
  136. };
  137. gc.PopupSound.prototype.updateTransform = function() {
  138. try {
  139. PIXI.Container.prototype.updateTransform.call(this);
  140. } catch(e) {
  141. }
  142. };