Jump to content

Button function with parameter


Raiper34
 Share

Recommended Posts

Hi, 

 

I am trying to pass parameter on click button action like this

this.backMenu = this.game.add.button(this.game.world.centerX, 0 - this.game.world.centerY + this.menuBackground.height/4, 'resume', function() {this.backMenuClick(this)});

But with this it does not work, when function is global and i do not use this, it works, but i need run selfs method of object...

 

Can anybody help me please? Thanks

Link to comment
Share on other sites

You need to pass the callback context as a parameter to game.add.button:

 

game.add.button(xykeycallbackcallbackContextoverFrameoutFramedownFrameupFrame,group) → {Phaser.Button}

 

so in your case:

 

this.backMenu = this.game.add.button(this.game.world.centerX, 0 - this.game.world.centerY + this.menuBackground.height/4, 'resume', function() {this.backMenuClick(this)}, this);

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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