Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

How do I get sprite index when clicked on


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


  • Recently Browsing   0 members

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