function ExperienceAppTimer() { if(!isExperienceMaestroAccount()) { return; } this.leftTime = ExperienceAppTimer.DEFAULT_LEFT_TIME_SEC; this.onTimeOver = null; var timeLeftText = game.add.text( game.world.centerX + ExperienceAppTimer.OFFSET_POS_X, game.world.height - ExperienceAppTimer.OFFSET_POS_Y, "앱 체험 종료까지 ", this.getFontStyle() ); timeLeftText.anchor.set(1, 0.5); timeLeftText.alpha = 0.5; // timeLeftText.stroke = '#000'; // timeLeftText.strokeThickness = 3; this.timerText = game.add.text( game.world.centerX + ExperienceAppTimer.OFFSET_POS_X, game.world.height - ExperienceAppTimer.OFFSET_POS_Y, this.getLeftTimeText(), this.getFontStyle() ); this.timerText.anchor.set(0, 0.5); // this.timerText.stroke = '#000'; // this.timerText.strokeThickness = 3; // this.setTimeLimit(4); this.loopTimer = game.time.events.loop(Phaser.Timer.SECOND, this.updateTimer, this); }; ExperienceAppTimer.prototype.getFontStyle = function() { return { font: "24px Arial", fill: "#f86", align: "left", boundsAlignH: "left", boundsAlignV: "bottom" }; } ExperienceAppTimer.prototype.getLeftTimeText = function() { return this.leftTime + " 초"; } ExperienceAppTimer.prototype.setTimeOverListener = function(onTimeOver) { this.onTimeOver = onTimeOver; } ExperienceAppTimer.prototype.setTimeLimit = function(leftTime) { this.leftTime = leftTime; this.timerText.text = this.getLeftTimeText(); } ExperienceAppTimer.prototype.updateTimer = function() { this.leftTime--; if(this.leftTime == 5) { this.timerText.fill = "#f42"; } else if(this.leftTime == 0) { this.timerText.fill = "#f00"; } if(this.leftTime > 0) { this.timerText.text = this.getLeftTimeText(); } else { this.timerText.text = this.getLeftTimeText(); if(this.loopTimer != null) game.time.events.remove(this.loopTimer); if(this.onTimeOver != null) this.onTimeOver(); } } ExperienceAppTimer.DEFAULT_LEFT_TIME_SEC = 20; ExperienceAppTimer.OFFSET_POS_X = 60; ExperienceAppTimer.OFFSET_POS_Y = 60;