From 72813d02de32400552cc53c9ff7e40bac8422660 Mon Sep 17 00:00:00 2001 From: Ian McGregor Date: Tue, 22 Nov 2016 13:56:25 +0000 Subject: [PATCH] Fix text align with compressed output js (#31) --- src/mixins/Text.js | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/mixins/Text.js b/src/mixins/Text.js index f77a0e09..d66e4b03 100755 --- a/src/mixins/Text.js +++ b/src/mixins/Text.js @@ -5,6 +5,9 @@ */ const p = PIXI.Text.prototype; +// Possible align values +const ALIGN_VALUES = ["center", "right", "left"]; + /** * Setter for the alignment, also sets the anchor point * to make sure the positioning is correct. @@ -19,24 +22,11 @@ const p = PIXI.Text.prototype; * @return {PIXI.Text} For chaining */ p.setAlign = p.g = function(align) { - this.style.align = align || "left"; - var x; if (typeof align == "string") { - switch (align) { - case "center": - x = 0.5; - break; - case "right": - x = 1; - break; - case "left": - x = 0; - break; - } - } else { - x = (align + 1) / 2; + align = ALIGN_VALUES.indexOf(align); } - this.anchor.x = x; + this.style.align = ALIGN_VALUES[align] || "left"; + this.anchor.x = (align + 1) / 2; return this; }; @@ -121,7 +111,7 @@ p.setShadow = p.sh = function(color, angle, distance) { /** * Check if a value is undefined, fallback to default value - * @method isUndefinedOr + * @method isUndefinedOr * @private * @param {*} value The value to check * @param {*} defaultValue The default value if value is undefined @@ -129,4 +119,4 @@ p.setShadow = p.sh = function(color, angle, distance) { */ var isUndefinedOr = function(value, defaultValue) { return value === undefined ? defaultValue : value; -}; \ No newline at end of file +};