var EHDI = EHDI || Object.create(null); EHDI.components = EHDI.components || Object.create(null); EHDI.components.pauseButton = function() { EHDI.displays.Button.call(this, EHDI.Assets.images["btn_pause"], null, null, null, 0.8); this.isPaused = false; this.isEndGame = false; this.setOnClickFunction(this.pauseGame.bind(this)); this.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.95, EHDI.GAME.sceneManager.getStageHeight() * 0.075); EHDI.GAME.pauseButton = this; window.addEventListener("blur", EHDI.GAME.pauseButton.pauseGame.bind(EHDI.GAME.pauseButton).bind(EHDI.GAME.pauseButton)); window.addEventListener("pagehide", EHDI.GAME.pauseButton.pauseGame.bind(EHDI.GAME.pauseButton)); window.addEventListener("webkitvisibilitychange", EHDI.GAME.pauseButton.checkInterrupt.bind(EHDI.GAME.pauseButton)); window.addEventListener("visibilitychange", EHDI.GAME.pauseButton.checkInterrupt.bind(EHDI.GAME.pauseButton)); EHDI.GAME.interrupt = true; }; EHDI.components.pauseButton.prototype = Object.create(EHDI.displays.Button.prototype); EHDI.components.pauseButton.prototype.checkInterrupt = function() { if (window.document.webkitHidden || window.document.hidden && !EHDI.GAME.saveData.isFirstTimePlay) { this.pauseGame(); } }; EHDI.components.pauseButton.prototype.pauseGame = function() { if(this.isPaused || this.isEndGame || EHDI.GAME.saveData.isFirstTimePlay) return; this.isPaused = true; EHDI.GAME.sceneManager.pushPopUp(new EHDI.popup.PausePopUp(), {y : new EHDI.scene.TransitionParameter(-EHDI.GAME.sceneManager.getStageHeight(), EHDI.GAME.sceneManager.getStageHeight() * 0.5), duration : 0.25}); }; EHDI.components.pauseButton.prototype.resumeGame = function() { this.isPaused = false; }; EHDI.components.pauseButton.prototype.endGame = function() { this.isEndGame = true; };