I'm new to Phaser 3 and trying to figure out the difference between the (at least) 3 methods to create rectangles. Here is the code
var game = new Phaser.Game({
scene: {
create: create
}
});
function create() {
let rect1 = this.add.rectangle(300, 100, 100, 30, 0x00f000, .5);
let rect2 = new Phaser.GameObjects.Rectangle(this, 300, 150, 100, 30, 0xf00000)
this.add.existing(rect2);
let rect3 = this.add.graphics({
fillStyle: {
color: 0x00f0f0
}
});
let rect = new Phaser.Geom.Rectangle(300, 200, 100, 30);
rect3.fillRectShape(rect);
}
<script src="https://cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.js"></script>
rect1 uses the simplest one which just needs 1 line of code.
rect2 instantiates the Phaser.GameObjects.Rectangle class. I guess it's more powerful if I need a bunch of rectangle-like objects where I can create a subclass of the class, predefine some properties and methods and instantiate my customized rectangle-like object.
rect3 uses Phaser.GameObjects.Graphics which I cannot image its use case where it beats the previous two. Could someone give me a hint?