Add: RoundedRect image texture for button sprite
This commit is contained in:
@@ -6,20 +6,6 @@ class RectSetting {
|
|||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
|
||||||
this.DEFAULT_BUTTON_COLORS = {
|
|
||||||
over: "#fff", // over
|
|
||||||
out: "#aaf", // out
|
|
||||||
down: "#faa", // down
|
|
||||||
disabled: "#333" // disabled
|
|
||||||
};
|
|
||||||
|
|
||||||
this.DEFAULT_TEXT_COLORS = {
|
|
||||||
over: "#000", // over
|
|
||||||
out: "#000", // out
|
|
||||||
down: "#000", // down
|
|
||||||
disabled: "#999" // disabled
|
|
||||||
};
|
|
||||||
|
|
||||||
if(buttonColors != null)
|
if(buttonColors != null)
|
||||||
this.buttonColors = buttonColors;
|
this.buttonColors = buttonColors;
|
||||||
else
|
else
|
||||||
@@ -44,44 +30,63 @@ RectSetting.DEFAULT_TEXT_COLORS = {
|
|||||||
|
|
||||||
class RoundRectButton {
|
class RoundRectButton {
|
||||||
constructor(roundRectSetting) {
|
constructor(roundRectSetting) {
|
||||||
this.outSprite = this.makeSprite(
|
this.buttonSprite = this.makeSprite(
|
||||||
roundRectSetting.width, roundRectSetting.height,
|
|
||||||
roundRectSetting.buttonColors.out
|
|
||||||
);
|
|
||||||
|
|
||||||
this.overSprite = this.makeSprite(
|
|
||||||
roundRectSetting.width, roundRectSetting.height,
|
|
||||||
roundRectSetting.buttonColors.over
|
|
||||||
);
|
|
||||||
|
|
||||||
this.downSprite = this.makeSprite(
|
|
||||||
roundRectSetting.width, roundRectSetting.height,
|
roundRectSetting.width, roundRectSetting.height,
|
||||||
roundRectSetting.buttonColors.down
|
roundRectSetting.buttonColors.down
|
||||||
);
|
);
|
||||||
|
|
||||||
this.disabledSprite = this.makeSprite(
|
this.makeText("Button text", this.buttonSprite);
|
||||||
roundRectSetting.width, roundRectSetting.height,
|
}
|
||||||
roundRectSetting.buttonColors.disabled
|
|
||||||
|
makeText(buttonText, button) {
|
||||||
|
let btnText = game.add.text(0, 0, buttonText,
|
||||||
|
{ font: "30px Arial", fill: "#fff" }
|
||||||
);
|
);
|
||||||
|
btnText.anchor.setTo(0.5);
|
||||||
|
|
||||||
|
button.addChild(btnText);
|
||||||
|
button.anchor.setTo(0.5, 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
makeSprite(width, height, color) {
|
makeSprite(width, height, color) {
|
||||||
|
let btnTexture = new Phaser.Graphics()
|
||||||
|
.beginFill(0x000000, 0.5)
|
||||||
|
.drawRoundedRect(0, 4, 200, 56, 5)
|
||||||
|
.endFill()
|
||||||
|
.generateTexture();
|
||||||
|
|
||||||
|
let button = game.add.sprite(0, 0, btnTexture);
|
||||||
|
|
||||||
|
return button;
|
||||||
|
/*
|
||||||
// create a new bitmap data object
|
// create a new bitmap data object
|
||||||
var bmd = game.add.bitmapData(width, height);
|
var bmd = game.add.bitmapData(width, height);
|
||||||
bmd.ctx.beginPath();
|
bmd.ctx.beginPath();
|
||||||
bmd.ctx.rect(0, 0, width, height);
|
bmd.ctx.rect(0, 0, width, height);
|
||||||
bmd.ctx.fillStyle = RectSetting.DEFAULT_BUTTON_COLORS.out;
|
bmd.ctx.fillStyle = color;
|
||||||
bmd.ctx.fill();
|
bmd.ctx.fill();
|
||||||
|
|
||||||
return game.add.sprite(
|
return game.add.sprite(
|
||||||
RoundRectButton.defaultPositionX,
|
RoundRectButton.defaultPositionX,
|
||||||
RoundRectButton.defaultPositionY, bmd
|
RoundRectButton.defaultPositionY, bmd
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
move(x, y) {
|
move(x, y) {
|
||||||
|
this.buttonSprite.x = x;
|
||||||
|
this.buttonSprite.y = y;
|
||||||
|
/*
|
||||||
this.outSprite.x = this.overSprite.x = this.downSprite.x = this.disabledSprite.x = x;
|
this.outSprite.x = this.overSprite.x = this.downSprite.x = this.disabledSprite.x = x;
|
||||||
this.outSprite.y = this.overSprite.y = this.downSprite.y = this.disabledSprite.y = y;
|
this.outSprite.y = this.overSprite.y = this.downSprite.y = this.disabledSprite.y = y;
|
||||||
|
|
||||||
|
this.outSprite.x = 0;
|
||||||
|
this.overSprite.x = 200;
|
||||||
|
this.downSprite.x = 400;
|
||||||
|
this.disabledSprite.x = 600;
|
||||||
|
|
||||||
|
this.overSprite.tint = 0xffaaaa; // "#faa"; //roundRectSetting.buttonColors.down;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user