From 5fe4604409372a429d030c543fcd85ed94e396d6 Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Wed, 11 Jun 2014 23:53:49 -0700 Subject: [PATCH] Word bubbles --- moonlight/js/moonlight-skulk.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/moonlight/js/moonlight-skulk.js b/moonlight/js/moonlight-skulk.js index 7b6518b..b452950 100644 --- a/moonlight/js/moonlight-skulk.js +++ b/moonlight/js/moonlight-skulk.js @@ -353,12 +353,7 @@ var AISprite = function(game, x, y, spritetype) { this.bubble_style = {font: '12px Arial Bold', fill: '#ffffff', align: 'center'} this.bubble = game.add.text(this.x, this.y - 20, this.bubble_text, this.bubble_style); - function destroybubble() { - this.bubble.destroy(); - this.bubble = null; - } - - setTimeout(destroybubble, 20000); + setTimeout(function(){this.clear_bubble = true;}, 20000); } this.update = function() @@ -376,7 +371,12 @@ var AISprite = function(game, x, y, spritetype) { if ( this.bubble !== null ) { this.bubble.destroy(); - this.bubble = game.add.text(this.x, this.y - 20, this.bubble_text, this.bubble_style); + if ( this.clear_bubble == true ) { + this.bubble = null; + this.clear_bubble = false; + } else { + this.bubble = game.add.text(this.x, this.y - 20, this.bubble_text, this.bubble_style); + } } switch ( game.rnd.integerInRange(0, 4) ) { @@ -411,6 +411,8 @@ var AISprite = function(game, x, y, spritetype) { 'townsfolk-guard-2' ]; this.bubble = null; + this.clear_bubble = false; + this.state = STATE_UNAWARE; Phaser.Sprite.call(this, game, x, y, spritenames_by_type[spritetype]); game.physics.arcade.enable(this);