SpeechBubble.prototype = Object.create(Phaser.Sprite.prototype); SpeechBubble.prototype.constructor = SpeechBubble; function SpeechBubble() { var textStyle = { font: "normal 24px Arial", fill: "#fff", align: "center" }; Phaser.Sprite.call(this, game, SpeechBubble.POSITION_X, SpeechBubble.POSITION_Y, ''); this.anchor.set(0.5); this.inputEnabled = false; game.add.existing(this); this.bgSprite = game.add.sprite(0, 0, ''); this.bgSprite.anchor.set(0.5); this.addChild(this.bgSprite); this.shadowSprite = game.add.sprite(0, 0, ''); this.shadowSprite.anchor.set(0.5); this.addChild(this.shadowSprite); this.outlineSprite = game.add.sprite(0, 0, ''); this.outlineSprite.anchor.set(0.5); this.addChild(this.outlineSprite); this.speechBubbleText = game.add.text(0, 0, "", textStyle); this.speechBubbleText.anchor.setTo(0.5); this.speechBubbleText.scale.set(1.3); this.addChild(this.speechBubbleText); } SpeechBubble.prototype.flipHorizontal = function(color) { this.bgSprite.scale.x *= -1; this.shadowSprite.scale.x *= -1; this.outlineSprite.scale.x *= -1; } SpeechBubble.prototype.setBgColor = function(color) { this.bgSprite.tint = color; } SpeechBubble.prototype.setShadowColor = function(color) { this.shadowSprite.tint = color; } SpeechBubble.prototype.setOutlineColor = function(color) { this.outlineSprite.tint = color; } SpeechBubble.prototype.setTextColor = function(color) { this.speechBubbleText.addColor(color, 0); } SpeechBubble.prototype.setText = function(content) { this.speechBubbleText.text = content; } SpeechBubble.prototype.setRoundSprite = function() { this.bgSprite.loadTexture("speech_round_bg"); this.shadowSprite.loadTexture("speech_round_shadow"); this.outlineSprite.loadTexture("speech_round_outline"); } SpeechBubble.prototype.setRectSprite = function() { this.bgSprite.loadTexture("speech_rect_bg"); this.shadowSprite.loadTexture("speech_rect_shadow"); this.outlineSprite.loadTexture("speech_rect_outline"); } SpeechBubble.prototype.setStarSprite = function() { this.bgSprite.loadTexture("speech_star_bg"); this.shadowSprite.loadTexture("speech_star_shadow"); this.outlineSprite.loadTexture("speech_star_outline"); } SpeechBubble.prototype.setDoubleStarSprite = function() { this.bgSprite.loadTexture("speech_double_star_bg"); this.shadowSprite.loadTexture("speech_double_star_shadow"); this.outlineSprite.loadTexture("speech_double_star_outline"); } SpeechBubble.prototype.move = function(x, y) { this.x = x; this.y = y; } SpeechBubble.prototype.startAnimation = function() { this.scale.set(0.7); this.show(); var tween = game.add.tween(this.scale); tween.to({x:1, y:1}, 200, Phaser.Easing.Linear.None, true, 0); tween.start(); game.time.events.add(Phaser.Timer.SECOND * 1, this.hide, this); } SpeechBubble.prototype.animateRoundSpeech = function(x, y, text) { this.setRoundSprite(); this.setBgColor(0xffffff); this.setShadowColor(0x00e0ff); this.setOutlineColor(0x0099ff); this.setTextColor("#0099ff"); this.setText(text); this.move(x, y); this.startAnimation(); } SpeechBubble.prototype.animateRectSpeech = function(x, y, text) { this.setRectSprite(); this.setBgColor(0xffffff); this.setShadowColor(0xffdd00); this.setOutlineColor(0xff9900); this.setTextColor("#ff9900"); this.setText(text); this.move(x, y); this.startAnimation(); } SpeechBubble.prototype.animateStarSpeech = function(x, y, text) { this.setStarSprite(); this.setBgColor(0xffffff); this.setShadowColor(0xff3000); this.setOutlineColor(0xff6600); this.setTextColor("#ff6600"); this.setText(text); this.move(x, y); this.startAnimation(); } SpeechBubble.prototype.animateDoubleStarSpeech = function(x, y, text) { this.setDoubleStarSprite(); this.setBgColor(0xffffff); this.setShadowColor(0xd00000); this.setOutlineColor(0xff0000); this.setTextColor("#ff0000"); this.setText(text); this.move(x, y); this.startAnimation(); } SpeechBubble.prototype.show = function() { this.alpha = 1; } SpeechBubble.prototype.hide = function() { this.alpha = 0; } SpeechBubble.prototype.destroySelf = function() { this.destroy(); } SpeechBubble.POSITION_X = God.POSITION_X - 200; SpeechBubble.POSITION_Y = God.POSITION_Y - 200; SpeechBubble.TYPE_ROUND = 0; SpeechBubble.TYPE_RECT = 1; SpeechBubble.TYPE_STAR = 2; SpeechBubble.TYPE_DOUBLE_STAR = 3;