Add: stroke and line spacing

This commit is contained in:
2018-05-03 16:14:32 +09:00
parent 8b0eb7898f
commit f1a263b882
2 changed files with 30 additions and 43 deletions
+21 -11
View File
@@ -27,16 +27,19 @@ RoundRectButtonSetting.DEFAULT_BUTTON_COLORS = {
RoundRectButtonSetting.DEFAULT_TEXT_COLORS = { RoundRectButtonSetting.DEFAULT_TEXT_COLORS = {
out: "#000", out: "#000",
over: "#000", over: "#333",
down: "#000", down: "#666",
disabled: "#999" disabled: "#999"
}; };
RoundRectButtonSetting.DEFAULT_TEXT_FONT = { RoundRectButtonSetting.DEFAULT_TEXT_FONT = {
font: "30px Arial", font: "30px Arial",
align: "center",
fill: "#fff" fill: "#fff"
}; };
RoundRectButtonSetting.DEFAULT_LINE_SPACING = -10; // pixels
class RoundRectButton { class RoundRectButton {
@@ -91,34 +94,37 @@ class RoundRectButton {
makeText(textContent) { makeText(textContent) {
let btnText = game.add.text(0, 0, textContent, this.setting.fontStyle); let btnText = game.add.text(0, 0, textContent, this.setting.fontStyle);
btnText.anchor.setTo(0.5); btnText.anchor.setTo(0.5);
btnText.lineSpacing = RoundRectButtonSetting.DEFAULT_LINE_SPACING;
return btnText; return btnText;
} }
move(x, y) {
this.button.x = x;
this.button.y = y;
}
mouseOut() { mouseOut() {
this.button.tint = this.setting.buttonColors.out; this.button.tint = this.setting.buttonColors.out;
this.text.tint = this.setting.textColors.out; this.text.fill = this.setting.textColors.out;
} }
mouseOver() { mouseOver() {
this.button.tint = this.setting.buttonColors.over; this.button.tint = this.setting.buttonColors.over;
this.text.tint = this.setting.textColors.over; this.text.fill = this.setting.textColors.over;
} }
mouseDown() { mouseDown() {
this.button.tint = this.setting.buttonColors.down; this.button.tint = this.setting.buttonColors.down;
this.text.tint = this.setting.textColors.down; this.text.fill = this.setting.textColors.down;
} }
buttonDisabled() { buttonDisabled() {
this.button.tint = this.setting.buttonColors.disabled; this.button.tint = this.setting.buttonColors.disabled;
this.text.tint = this.setting.textColors.disabled; this.text.fill = this.setting.textColors.disabled;
}
move(x, y) {
this.button.x = x;
this.button.y = y;
} }
get inputEnabled() { get inputEnabled() {
@@ -134,6 +140,10 @@ class RoundRectButton {
this.buttonDisabled(); this.buttonDisabled();
} }
} }
set lineSpacing(spacingInPixels) {
this.text.lineSpacing = spacingInPixels;
}
} }
RoundRectButton.defaultRoundAmount = 10; RoundRectButton.defaultRoundAmount = 10;
@@ -1,38 +1,6 @@
///////////////////////////// /////////////////////////////
// Main game // Main game
/**** Phaser3 *****
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 200 }
}
},
scene: {
preload: preload,
create: create
}
};
var game = new Phaser.Game(config);
function preload() {
}
function create() {
console.log(game);
this.cameras.main.setBackgroundColor('#4d4d4d');
// game.stage.backgroundColor = '#4d4d4d';
// graphics = game.add.graphics(0, 0);
}
*/
var game = new Phaser.Game(1000, 800, Phaser.CANVAS, "RoundRectButton", var game = new Phaser.Game(1000, 800, Phaser.CANVAS, "RoundRectButton",
{preload:preload, create:create, update:update, render:render}); {preload:preload, create:create, update:update, render:render});
@@ -48,8 +16,17 @@ function create() {
graphics = game.add.graphics(0, 0); graphics = game.add.graphics(0, 0);
let setting = new RoundRectButtonSetting(200, 100); let setting = new RoundRectButtonSetting(200, 100);
setting.fontStyle = {
fontSize: "30px",
align: "center",
fontWeight: "",
stroke: "red",
strokeThickness: 5
};
let button = new RoundRectButton(setting, "둥근 모서리\n버튼", dummy); let button = new RoundRectButton(setting, "둥근 모서리\n버튼", dummy);
button.move(200, 200); button.move(200, 200);
// button.lineSpacing = -10;
} }
function dummy() { function dummy() {