abdel

Undestand onPointerDown [Help]

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.