Jump to content

Text click event does not work


super_frog
 Share

Recommended Posts

I am trying to add click event to a text (game.add.text), but it is not working for me.

I've seen an example and tried to implement, but I get an error saying 'Cannot read property 'onInputDown' of undefined'.

 

The code is:



var btn = game.add.text(game.world.centerX, game.world.centerY, 'blah1');
btn.inputEnabled = true;  
btn.events.onInputDown.add(function (){alert("blah2");}, this);


 

The code is place in:



PlayGround.gameOver =
{
    create: function ()
    {
    // here is placed the above code
    }
}


 

What am I doing wrong?

Link to comment
Share on other sites

Hi, Here's example code
var btn = game.add.text(game.world.centerX, game.world.centerY, 'PLAY', {font: '40px Impact', fill: 'black', align: 'center'}).anchor.set(.5);btn.inputEnabled = true;btn.events.onInputDown.add(play, this);

I've tried with this.game, but the same error occurs.

Link to comment
Share on other sites

  • 8 months later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...