Hi there,
I’m trying to align a group of Objects (text) in the middle of the scene. Phaser.Actions.GridAlign()
seems to be the “right tool” for that. And even though centering is kinda ok, it still confuses me, especially if I do set x
and y
to 0.
So take a look.
create() {
this.drawMainMenu()
}
drawMainMenu(){
this._menu = this.add.group({
name: 'game_scene_menu',
active: true,
})
const menuButtonsLabels = ['Play', 'Settings', '----Quit----']
menuButtonsLabels.forEach((btnTitle) => {
const menuBtn = new TextButton(this, 0, 0, btnTitle, buttonFontStyle)
this.menu.add(menuBtn)
this.add.existing(menuBtn) // is there a way to skip this ?
})
Phaser.Actions.GridAlign(this.menu.getChildren(), {
width: 1, // max 1 in a "row"
height: -1,
cellWidth: 140,
cellHeight: 70,
position: Phaser.Display.Align.TOP_LEFT,
x: 0, // actually to top-left
y: 0 // actually to top-left
});
}
But the menu is off-screen (see the screen #1)
Why is it so off-screen ?
I get much better results if I use this.cameras.main.midPoint
I also added some fake menu-buttons to menuButtonsLabels
just to see how it scales.
const sceneCenterPoint = this.cameras.main.midPoint
Phaser.Actions.GridAlign(this._mainMenu.getChildren(), {
width: 1,
height: -1,
cellWidth: menuItemWidth,
cellHeight: fontSize + 6,
position: Phaser.Display.Align.CENTER,
x: sceneCenterPoint.x,
y: sceneCenterPoint.y
});
It is centered, but it’s kinda grows to the bottom.
Do I miss something?