alessa Posted May 31, 2018 Share Posted May 31, 2018 I have two texts on my interface, one used to start the game and the other one for some calibration. How can I get access to the element that has been actually clicked? Here's my code for now.. this.startText = this.add.text(400, 300, 'START', { fill: 'white', fontFamily: CONST.fonts.default, fontSize: 48 }) this.otherText = this.add.text(400, 300, 'CALIBRATION', { fill: 'white', fontFamily: CONST.fonts.default, fontSize: 48 }) // make the text interactive this.startText.setInteractive(new Phaser.Geom.Rectangle(0, 0, this.startText.width, this.startText.height), Phaser.Geom.Rectangle.Contains); // listen for clicks on it this.input.on('pointerdown', function (pointer){ // here I should have something like "if text is START, then do something; if it's CALIBRATION, do something else" }); Any tip in merit? Cheers! Link to comment Share on other sites More sharing options...
YuPi Posted May 31, 2018 Share Posted May 31, 2018 Instead of this.input.on... use: this.startText.on('pointerdown', function () { // this here refers to this.startText, so you can do e.g. this.setText("new text"); }) This works on Images, so I expect it to work also on text and other game objects. lumosmind 1 Link to comment Share on other sites More sharing options...
alessa Posted May 31, 2018 Author Share Posted May 31, 2018 36 minutes ago, YuPi said: Instead of this.input.on... use: this.startText.on('pointerdown', function () { // this here refers to this.startText, so you can do e.g. this.setText("new text"); }) This works on Images, so I expect it to work also on text and other game objects. Indeed it worked, thanks! Is there a place where these kind of documentation is easily accessible for a total beginner? Link to comment Share on other sites More sharing options...
YuPi Posted June 1, 2018 Share Posted June 1, 2018 Here are the examples: https://labs.phaser.io/index.html?dir=&q= and here is the documentation: https://photonstorm.github.io/phaser3-docs/list_class.html Link to comment Share on other sites More sharing options...
Recommended Posts