From 3634e2bf015e1a04c07a59028a46b68e4831f637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Mon, 7 May 2018 10:42:37 +0900 Subject: [PATCH] Fix: button text align --- src/game/lib/back_button.js | 2 ++ src/game/lib/round_rect_button.js | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/game/lib/back_button.js b/src/game/lib/back_button.js index 748eba1..a67ce3e 100644 --- a/src/game/lib/back_button.js +++ b/src/game/lib/back_button.js @@ -2,6 +2,8 @@ class BackButton { constructor(clickEvent) { let setting = new RoundRectButtonSetting(50, 50); + setting.fontStyle.boundsAlignH = "center"; // left, center. right + setting.fontStyle.boundsAlignV = "middle"; // top, middle, bottom setting.setStrokeColor( 0x884444, 0xaa6666, diff --git a/src/game/lib/round_rect_button.js b/src/game/lib/round_rect_button.js index 9b2ae6c..04273d6 100644 --- a/src/game/lib/round_rect_button.js +++ b/src/game/lib/round_rect_button.js @@ -123,6 +123,7 @@ class RoundRectButton { let width = this.setting.width - this.setting.strokeWidth * 2; let height = this.setting.height - this.setting.strokeWidth * 2; let innerRoundAmount = this.setting.roundAmount * (width / this.setting.width); + let btnTexture = new Phaser.Graphics() .beginFill(0xffffff) .drawRoundedRect(this.setting.strokeWidth, this.setting.strokeWidth, width, height, innerRoundAmount) @@ -133,8 +134,11 @@ class RoundRectButton { } makeText(textContent) { + let width = this.setting.width - this.setting.strokeWidth * 2; + let height = this.setting.height - this.setting.strokeWidth * 2; + let btnText = game.add.text(0, 0, textContent, this.setting.fontStyle) - .setTextBounds(0, 0, this.setting.width, this.setting.height); + .setTextBounds(0, 0, width, this.setting.height); btnText.lineSpacing = RoundRectButtonSetting.DEFAULT_TEXT_LINE_SPACING_PX; // btnText.anchor.setTo(0.5);