Jump to content

Undestand onPointerDown [Help]


abdel
 Share

Recommended Posts

hy,

I have an array of players Id that I should pass the corresponding one to a function when I click on a sprite.

create () {

                var players = [123, 234, 222, 333];

                var playButs = [];

                for (var i = 0; i < 4; i++) {

                               playButs.push(null);

                }

                for (i = 0; i < 4; i++) {

                               playButs[i] = this.add.sprite(70, 10*i+20, 'sheet', 'arrow');

                               playButs[i].setScale(1);

                               playButs[i].setOrigin(0);

                               playerId = players[i];

                               playButs[i].setInteractive().on('pointerdown', function(){this._play(playerId)}, this);

                }

}



_play(playerId){

                console.log("PlayId After: "+playerId);

                //Always show 333

}


the is that when I click on sprite the _play function get always the last item of players array instead on corresponding player.

 

thank you

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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