Phaser 3 how to center rectangle

var progressBox = this.add.graphics();
progressBox.fillStyle(0x222222, 0.8);
progressBox.fillRect(240, 270, 320, 50);

I have this. As you can see , i provided 240,270 as x,y. But i want it to be centered exactly depending on the user’s device’s screen’s sizes.

What should I do? get the device screen sizes via javascript and pass them to this function ? or any other ideas?

You can use the Phaser scale manager for that. It is accessible from any scene like this:

   var gameWidth = this.scale.width;
   var gameHeight = this.scale.height;