I want to make a button which toggles its image when I click.
I tried to use the following code;
export class CardImage extends Phaser.GameObjects.Container {
constructor(scene, x, y, id, children) {
super(scene, x, y, children);
scene.add.existing(this);
this.setSize(150, 200);
this.setInteractive();
this.add(scene.add.image(0, 0, 'cards', id)).setScale(.5);
this.original = this.list[0];
this.original.setDepth(4);
this.add(scene.add.image(0, 0, 'chosen_cards', id)).setScale(.5);
this.toggled = this.list[1];
this.toggled.setDepth(-31);
this.id = id;
this.chosen = false;
}
toggle() {
if (this.chosen) {
this.original.setDepth(-31);
this.selected.setDepth(4);
this.chosen = false;
}
else {
this.selected.setDepth(-31);
this.original.setDepth(4);
this.chosen = true;
}
}
}
But, it showed the problem that this button always showing the toggled image, not original image.
can you tell me what is the problem?
Also, it seems the image from spriteset cannot resize by using setDisplaySize; am I correct on it?