Jump to content

How do I get sprite index when clicked on


Kobaltic
 Share

Recommended Posts

Which index are you referring to?

Is it in a group?

Or did you assign the sprite an index like 'sprite.index = value'?

 

Either way, the sprite is the first argument passed to the callback function assigned to the click.

//Create a spritevar sprite = game.add.sprite(...);//Give it an indexsprite.index = 0;//Enable inputsprite.inputEnabled = true;//Add callbacksprite.events.onInputDown.add(clickCallback, this);//Put it in a groupgroup.add(sprite);clickCallback = function(sprite){    console.log(sprite.index);    console.log(group.getIndex(sprite));}
Link to comment
Share on other sites

Thanks for the quick responses. It turns out that I really wanted to pass the sprite as an argument into the call back. I didn't think that was possible but since it is I just passed the sprite through and it now works as expected.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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