In lobby scene I create filter, which player can use that find a similar match. I have text, sprites, images, and containers.
Code under create function below:
create() {
this.bg = this.add.graphics().fillStyle(RummyConstants.BACKGROUND_COLOR, 1)
.fillRect(0, 0, ResponsiveHelper.currentWidth, ResponsiveHelper.currentHeight);
//region Panel body
let panelHeader = this.add.graphics().fillStyle(RummyConstants.LOBBY_PANEL_HEADER_COLOR, 1)
.fillRoundedRect(0, 0,
ResponsiveHelper.currentWidth - (ResponsiveHelper.getX(26) * 2),
ResponsiveHelper.currentHeight - (ResponsiveHelper.getY(17) * 2), 10);
let headerText = this.make.text({
x: ResponsiveHelper.getX(24),
y: ResponsiveHelper.getY(6),
text: 'Lobby',
origin: {x: 0, y: 0},
style: {
font: 'bold 24px Roboto',
}
}).setScale(ResponsiveHelper.ratioX);
this.balanceText = this.make.text({
x: ResponsiveHelper.getX(550),
y: ResponsiveHelper.getY(9),
text: 'â‚ą 10000 INR',
origin: {x: 0, y: 0},
style: {
font: 'bold 16px Roboto',
}
}).setScale(ResponsiveHelper.ratioX);
let lobbyButtons = this.buttonsHelper.createLobbyButtons();
lobbyButtons.setPosition(ResponsiveHelper.getX(650), ResponsiveHelper.getY(8))
.setScale(ResponsiveHelper.ratioX);
let panelBody = this.add.graphics().fillStyle(RummyConstants.LOBBY_PANEL_BODY_COLOR, 1)
.fillRoundedRect(ResponsiveHelper.getX(1),ResponsiveHelper.getY(41),
ResponsiveHelper.currentWidth - (ResponsiveHelper.getX(27) * 2),
ResponsiveHelper.currentHeight - (ResponsiveHelper.getY(58 + 18) ),
{
tl: 0,
tr: 0,
bl: 10,
br: 10
});
this.add.container(ResponsiveHelper.getX(26), ResponsiveHelper.getY(17),
[panelHeader, headerText, this.balanceText, lobbyButtons, panelBody]);
//endregion
//region left section container
let playersCountButtons = this.buttonsHelper.createPlayersCountLobbyButtons();
let playersCountButtonsContainer = this.add.container(ResponsiveHelper.getX(52), ResponsiveHelper.getY(78),
playersCountButtons);
let pointsValueSection = this.setPointsValueSection();
let pointsValueSectionContainer = this.add.container(ResponsiveHelper.getX(52), ResponsiveHelper.getY(167),
pointsValueSection);
this.entryFee = this.buttonsHelper.createStrokeButton(0, 0,
188,42,false,'ENTRY FEE: â‚ą ');
this.setPointsValueText();
let playButton = this.buttonsHelper.createGradientButton(198, 0,
136,42,
RummyConstants.BLUE_BUTTON_TOP_GRADIENT_COLOR,RummyConstants.BLUE_BUTTON_BOTTOM_GRADIENT_COLOR,
'Play Now');
playButton.button.on('pointerdown',()=>{
this.gameScript.createOrJoinMatch(this.playersCount, 800, 10)
.then(r =>(console.log('good')));
},this);
let playSectionContainer = this.add.container(ResponsiveHelper.getX(52), ResponsiveHelper.getY(291),
[this.entryFee.button, this.entryFee.disableStroke, this.entryFee.enableStroke, this.entryFee.buttonText,
playButton.button, playButton.buttonText]);
playButton.mask.setPosition(playButton.button.x+playSectionContainer.x, playButton.button.y+playSectionContainer.y)
let separatingLine = this.add.image(ResponsiveHelper.getX(414),ResponsiveHelper.getY(79),
'separating_line').setOrigin(0,0).setScale(ResponsiveHelper.ratioY);
// let leftSectionContainer = this.add.container(ResponsiveHelper.getX(0), ResponsiveHelper.getY(0),
// [playersCountButtonsContainer,pointsValueSectionContainer,playSectionContainer,separatingLine]);
//endregion
//region right section container
let hotTableImage = this.add.image(0,0, 'hot')
.setOrigin(0,0).setTint(0xFE0000).setScale(ResponsiveHelper.ratioX);
let hotTableText = this.make.text({
x: ResponsiveHelper.getX(20),
y: 2,
text: 'Join Our Hottest Tables',
origin: {x: 0, y: 0},
style: {
font: '14px Roboto',
}
}).setScale(ResponsiveHelper.ratioX);
//TODO: hot tables pagination
let headerHotTableSectionContainer = this.add.container(ResponsiveHelper.getX(449), ResponsiveHelper.getY(84),
[hotTableImage,hotTableText]);
//endregion
}
setPointsValueSection(){
let line1 = this.add.sprite(0,0,'line').setOrigin(0,0).setScale(ResponsiveHelper.ratioX,-ResponsiveHelper.ratioX);
let line2 = this.add.sprite(0,ResponsiveHelper.getY(63),'line').setOrigin(0,0).setScale(ResponsiveHelper.ratioX);
for (let i = 0; i <5; i++) {
this.pointsValueList.push(
this.make.text({
x: ResponsiveHelper.getX(31+24+55*i),
y: ResponsiveHelper.getY(20),
text: '0.0',
origin: {x: 0.5, y: 0},
style: {
font: '22px Roboto',
}
}).setScale(ResponsiveHelper.ratioX)
)
}
let arrow1 = this.add.sprite(ResponsiveHelper.getX(3), ResponsiveHelper.getY(20), 'arrow').setOrigin(0, 0).setInteractive()
.on('pointerdown', () => {
this.pointsValueText.unshift(...this.pointsValueText.splice(this.pointsValueText.length-1,1));
this.setPointsValueText();
this.buttonsHelper.clickSound.play();
}, this).setScale(ResponsiveHelper.ratioX);
let arrow2 = this.add.sprite(ResponsiveHelper.getX(321), ResponsiveHelper.getY(20), 'arrow').setOrigin(0, 0).setInteractive()
.on('pointerdown', () => {
this.pointsValueText.unshift(...this.pointsValueText.splice(1,this.pointsValueText.length-1));
this.setPointsValueText();
this.buttonsHelper.clickSound.play();
}, this).setScale(-ResponsiveHelper.ratioX,ResponsiveHelper.ratioX);
let text = this.make.text({
x: ResponsiveHelper.getX(130),
y: ResponsiveHelper.getY(75),
text: 'POINTS VALUE',
origin: {x: 0, y: 0},
style: {
font: '10px Roboto',
}
}).setTint(0x0AA9DB).setScale(ResponsiveHelper.ratioX);
return [line1,line2,arrow1,arrow2,text,this.pointsValueList[0],this.pointsValueList[1],this.pointsValueList[2],
this.pointsValueList[3],this.pointsValueList[4]]
}
setPointsValueText(){
for (let i = 0; i <5; i++) {
this.pointsValueList[i].text = this.pointsValueText[i].toFixed(1);
this.pointsValueList[i].alpha = 0.3;
}
this.pointsValueList[2].alpha = 1;
this.entryFee.buttonText.text = 'ENTRY FEE: â‚ą '+ (Number(this.pointsValueList[2].text) * 80);
}
In my ButtonsHelper I have function, that helps me create a buttons:
createGradientButton(x, y, width, height, topGradient, bottomGradient, text) {
let button = this.scene.make.graphics({x: 0, y: 0, add: true})
.fillGradientStyle(topGradient, topGradient, bottomGradient, bottomGradient, 1)
.fillRect(x, y, width, height)
.setInteractive({
// useHandCursor: true,
hitArea: new Phaser.Geom.Rectangle(x, y, width, height),
hitAreaCallback: Phaser.Geom.Rectangle.Contains,
}).on('pointerdown', () => {
this.clickSound.play();
}, this)
.setScale(ResponsiveHelper.ratioX);
let mask = this.scene.make.graphics({x: 0, y: 0, add: true})
.fillStyle(0xFFFFFF, 0)
.fillRoundedRect(x, y, width, height, 4)
.setScale(ResponsiveHelper.ratioX).setName("mask");
button.setMask(mask.createGeometryMask());
let buttonText = this.scene.make.text({
x: (x + width / 2) * ResponsiveHelper.ratioX,
y: (y + height / 2) * ResponsiveHelper.ratioX,
text: text,
origin: {x: 0.5, y: 0.5},
style: {
font: '14px Roboto',
}
}).setScale(ResponsiveHelper.ratioX);
return {button, mask, buttonText}
}