Fix: refactoring appButton

This commit is contained in:
2018-06-02 22:12:19 +09:00
parent 73bdb38c56
commit e3bcd3bb12
13 changed files with 216 additions and 37 deletions
+22 -4
View File
@@ -79,7 +79,7 @@ RoundRectButtonSetting.DEFAULT_STROKE_WIDTH_PX = 5; // in pixel
class RoundRectButton {
constructor(roundRectSetting, buttonText, clickEvent) {
constructor(roundRectSetting, iconName, buttonText, clickEvent) {
this.setting = roundRectSetting;
this.clickEvent = clickEvent;
@@ -88,10 +88,18 @@ class RoundRectButton {
this.buttonStroke.inputEnabled = true;
this.setEventMethod(this.buttonStroke);
this.text = this.makeText(buttonText);
this.button = this.makeButtonSprite();
this.button.addChild(this.text);
this.text = this.makeText(buttonText);
if(buttonText.length > 0) {
this.button.addChild(this.text);
}
if(iconName.length > 0) {
this.icon = this.makeIcon(iconName);
this.setIcon(this.icon);
}
// this.button.anchor.setTo(0.5, 0.5);
this.button.inputEnabled = true;
this.setEventMethod(this.button);
@@ -136,6 +144,14 @@ class RoundRectButton {
return game.add.sprite(0, 0, btnTexture);
}
makeIcon(iconName) {
let icon = game.add.sprite(0, 0, iconName);
icon.width = 80;
icon.height = 80;
return icon;
}
makeText(textContent) {
let width = this.setting.width - this.setting.strokeWidthPx * 2;
let height = this.setting.height - this.setting.strokeWidthPx * 2;
@@ -225,3 +241,5 @@ class RoundRectButton {
}
}
RoundRectButton.NONE_ICON = "";
RoundRectButton.NONE_BUTTON_TEXT = "";