Apologies if this is very basic, but having some problems extending a text object. Alpha and visibility no longer seem to work. Tried as a sprite also. I’m sure it’s something simple I’m overlooking.
I would assume alpha and visibility would just work having extended a class that contains them?
Class
export default class Button extends Phaser.GameObjects.Text {
constructor(x, y, label, scene, callback) {
super (scene, x, y)
this.scene = scene;
this.x = x;
this.y = y;
this.alpha;
console.log(this.alpha); // RETURNS AS 1.
const border = scene.add.text(x -2, y -2, label)
.setOrigin(0)
.setPadding(12)
.setStyle({ fontFamily: 'K2D-Regular', fontSize: '18px', fill: '#FFF', backgroundColor: '#46aafe' })
.setInteractive({ useHandCursor: true })
.on('pointerover', () => button.setStyle({ }))
.on('pointerout', () => button.setStyle({ }));
const btn = scene.add.text(x, y, label)
.setOrigin(0)
.setPadding(10)
.setStyle({ fontFamily: 'K2D-Regular', fontSize: '18px', fill: '#FFF', backgroundColor: '#13173c' })
.setInteractive({ useHandCursor: true })
.on('pointerdown', () => callback())
.on('pointerover', () => btn.setStyle({ backgroundColor: '#4d2359' }))
.on('pointerout', () => btn.setStyle({ backgroundColor: '#13173c' }));
}
}
In the scene
Alpha is logged as 0 but the button is still visible.
changeLanguage = new Button(150, 150, '< GO BACK', this, () => this.showLanguages());
changeLanguage.alpha = 0;
console.log (changeLanguage.alpha);
EDIT: Looks like I can’t set any properties of it within a scene once it’s created. X/Y etc. Help!
Thanks!