I have a container containing an image and some text; We are facing an issue with the interactive hitarea of the container
this.image = this.add.image(0, 0, 'GreenButtonBox').setOrigin(0.5).setScale(2);
this.text = this.add.text(0, 0, "Click", { font: "bold 35px Arial", fill: '#ffffff' }).setOrigin(0.5).setScale(1);
this.container = this.add.container(400, 400, [this.image, this.text])
.setSize(this.image.width, this.image.height)
.setInteractive()
.on('pointerup', this.SubmitAnswer);
In the case above the interactive part of the button is located in the middle (maybe due to the scale of the image?
I also tried adding new Phaser.Geom.Rectangle to the interactive function as such
.setInteractive(new Phaser.Geom.Rectangle(0, 0, this.image.width, this.image.height), Phaser.Geom.Rectangle.Contains)
but the clickable area become the lower right corner of the button; wheras with
.setInteractive(new Phaser.Geom.Rectangle((this.image.width / 2) * -1, (this.image.height / 2) * -1, this.image.width, this.image.height), Phaser.Geom.Rectangle.Contains)
the clickable area becomes the uper left part of the button;
Do I need to account for the scale myself? such as
.setInteractive(new Phaser.Geom.Rectangle((this.image.width / 2) * -1, (this.image.height / 2) * -1, this.image.width * 2, this.image.height * 2), Phaser.Geom.Rectangle.Contains)
This actually works
I'm confused as to why I need to scale the image again when I'm taking the image width and height for the container width and height.
Am I missing something?